Manage iMessage with python
Project description
Lusid
If you have the following:
- Macbook
- Python
You can programatically control iMessage, here's how
Quickstart
- Install the dependency
$ pip install lusid
$ # Or pipenv install lusid...
- Create a "client" to repeatedly read your inbox (the rest of this quickstart assumes you're writing to a file named
app.pybut feel free to replace that later on with whatever you named your to)
# app.py
from lusid import create_simple_message_reader
def start_client():
create_simple_message_reader(
message_handler=lambda to, body: None
)
if __name__ == "__main__":
start_client()
- Define a function for handling messages:
# Snippet
def handle_message(from, body, send_message):
print(f"Handling the message [{body}] from [{from}]")
send_message(from, "Some funny autoreply here")
Similar to a "response" variable in web handlers, the send_message parameter provides a method to send a message
- Next we're going to include the function we defined earlier
# app.py
from lusid import create_simple_message_reader
+def handle_message(from, body, send_message):
+ print(f"Handling the message [{body}] from [{from}]")
+ send_message(from, "Some funny autoreply here")
def start_client():
create_simple_message_reader(
message_handler=lambda to, body: None
)
if __name__ == "__main__":
start_client()
Then actually use it as our message handler
# app.py
from lusid import create_simple_message_reader
def handle_message(from, body, send_message):
print(f"Handling the message [{body}] from [{from}]")
send_message(from, "Some funny autoreply here")
def start_client():
create_simple_message_reader(
- message_handler=lambda to, body: None
+ message_handler=handle_message
)
if __name__ == "__main__":
start_client()
- Now your script is set up to automatically reply to every received message with "Some funny autoreply here"
$ python app.py
Some terminal output indicating it's running...
Additional methods
Architecture
If you're wondering how this works under the hood there are two components:
- Reading messages
- Sending messages
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lusid_yevbarkalov-0.0.1.tar.gz.
File metadata
- Download URL: lusid_yevbarkalov-0.0.1.tar.gz
- Upload date:
- Size: 2.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9976dc6a6715edde09d91b8fbd0ce1e79d3c0f47657cb51ef964f899e5a20641
|
|
| MD5 |
7a6d3ca142053bfee6cea27351bd1b51
|
|
| BLAKE2b-256 |
4a58147b6de3c9cfa84a80bd3016cb7896a6897dc0191c225054cd3d7f66aaaf
|
File details
Details for the file lusid_yevbarkalov-0.0.1-py3-none-any.whl.
File metadata
- Download URL: lusid_yevbarkalov-0.0.1-py3-none-any.whl
- Upload date:
- Size: 3.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e552a491a2a163f2f45d1c714f9de88b1e5870d724961d9b5f849b716766d95
|
|
| MD5 |
157bdfb0e1430793a731eaa41a6fd357
|
|
| BLAKE2b-256 |
7641bd837497064e19a534343c7d4cb2eb6e89c181d5330fa0676ed9d5e323b5
|