Created
October 2, 2018 00:59
-
-
Save erikrose/d7f6eb08f8bacd1a8d77896af96e98d3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python | |
""" | |
Make a folder of links to Agenda notes so you can open them via LaunchBar. This | |
allows you to switch quickly between notes from the keyboard, which I haven't | |
yet figured out how to do with Agenda alone. | |
It takes a single argument:: | |
makeNoteLinks.py the_folder_you_index_with_launchbar | |
You may need to set the file as executable first:: | |
chmod a+x makeNoteLinks.py | |
If 2 notes (even in different categories or projects) have the same name, the | |
last one (by UUID) will win. If I end up using this long-term, I may represent | |
categories and projects as folders. | |
""" | |
from os.path import expanduser, join | |
from sqlite3 import connect | |
from sys import argv | |
def clean(title): | |
"""Return a filesystem-valid name given the title of a note.""" | |
return title.replace('/', '-') | |
def make_link(id, title, dest_dir): | |
"""Make a single .inetloc file that points to the given note.""" | |
TEMPLATE = """<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>URL</key> | |
<string>agenda://note/%s</string> | |
</dict> | |
</plist> | |
""" | |
with open(join(dest_dir, clean(title) + '.inetloc'), 'w') as file: | |
file.write(TEMPLATE % id) | |
def main(dest_dir): | |
with connect(expanduser('~/Library/Containers/com.momenta.agenda.macos/Data/Documents/Agenda/DerivedInfo/UI Database/UIDatabase.db')) as conn: | |
c = conn.cursor() | |
for id, title in c.execute('select ZIDENTIFIER, ZTITLE from ZSECTION order by ZIDENTIFIER'): | |
make_link(id, title, dest_dir) | |
if __name__ == '__main__': | |
main(argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment