Skip to main content

Manage iMessage with python

Project description

Lusid

If you have the following:

  • Macbook
  • Python

You can programatically control iMessage, here's how

Quickstart

  1. Install the dependency
$ pip install lusid
$ # Or pipenv install lusid...
  1. Create a "client" to repeatedly read your inbox (the rest of this quickstart assumes you're writing to a file named app.py but 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()
  1. 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

  1. 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()
  1. 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:

  1. Reading messages
  2. Sending messages

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lusid_yevbarkalov-0.0.1.tar.gz (2.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lusid_yevbarkalov-0.0.1-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

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

Hashes for lusid_yevbarkalov-0.0.1.tar.gz
Algorithm Hash digest
SHA256 9976dc6a6715edde09d91b8fbd0ce1e79d3c0f47657cb51ef964f899e5a20641
MD5 7a6d3ca142053bfee6cea27351bd1b51
BLAKE2b-256 4a58147b6de3c9cfa84a80bd3016cb7896a6897dc0191c225054cd3d7f66aaaf

See more details on using hashes here.

File details

Details for the file lusid_yevbarkalov-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for lusid_yevbarkalov-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3e552a491a2a163f2f45d1c714f9de88b1e5870d724961d9b5f849b716766d95
MD5 157bdfb0e1430793a731eaa41a6fd357
BLAKE2b-256 7641bd837497064e19a534343c7d4cb2eb6e89c181d5330fa0676ed9d5e323b5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page