Skip to content

Instantly share code, notes, and snippets.

@evilsocket
Last active October 19, 2022 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evilsocket/39f2436e7f9c6ddcfc99f744490d4df0 to your computer and use it in GitHub Desktop.
Save evilsocket/39f2436e7f9c6ddcfc99f744490d4df0 to your computer and use it in GitHub Desktop.
Read Apple Notes content in python via quick&dirty AppleScript
def get_apple_note_contents(account = 'iCloud', folder = 'Notes', note = 'Routine', strip_tags = True, as_lines = True):
import subprocess
import os
import tempfile
import re
script = """
tell application "Notes"
tell account "%s"
tell folder "%s"
get body of note "%s"
end tell
end tell
end tell
""" % (account, folder, note)
_, file_path = tempfile.mkstemp(suffix='.tmp')
with open(file_path, 'w+t') as fp:
fp.write(script)
out = subprocess.getoutput("osascript %s" % file_path)
os.unlink(file_path)
if strip_tags:
out = re.sub('<[^<]+?>', '', out)
return out.split("\n") if as_lines else out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment