-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathgetFavorites.py
30 lines (26 loc) · 881 Bytes
/
getFavorites.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import plistlib
import os
import json
filePath = os.path.expanduser("~/Library/Application Support/DEVONthink 3/Favorites.plist")
result = {"items": []}
if os.path.exists(filePath):
try:
plObjList = plistlib.load(open(filePath, "rb"))
except AttributeError:
plObjList = plistlib.readPlist(filePath)
for plobj in plObjList:
if "UUID" in plobj:
result["items"].append({
"title": plobj["Name"],
# "subtitle": "",
"arg": plobj["UUID"]})
else:
pass
# when favourite item is a db, plobj has keys: alias, date, path
# alias can be read by 'plobj["Alias"].data'
if result["items"]:
print(json.dumps(result))
else:
print('{"items": [{"title": "No Favorite Item","subtitle": "(*´・д・)?"}]}')