Last active
October 19, 2022 18:35
-
-
Save evilsocket/39f2436e7f9c6ddcfc99f744490d4df0 to your computer and use it in GitHub Desktop.
Read Apple Notes content in python via quick&dirty AppleScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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