Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 39 additions & 13 deletions getTagsList.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,48 @@
import shlex
import subprocess

selectedDbUUID = os.getenv('selectedDbUUID', "")
def runForCertainDB(selectedDbUUID):
cmdScript = "osascript -e 'tell application \"DEVONthink 3\" to get name of tag group of (get database with uuid \"{}\")' -s s".format(selectedDbUUID)
cmdList = shlex.split(cmdScript)
cmdResult = subprocess.check_output(cmdList)
tagList = ast.literal_eval(
"[" + cmdResult[1:-2].decode("UTF8") + "]")

result = []
for tag in tagList:
result.append({
"title": tag,
"subtitle": "Press Enter to list all files with this tag",
# "arg": tag,
"variables": {"selectedTag": tag, "selectedDbUUID": selectedDbUUID}
})
return result

cmdScript = "osascript -e 'tell application \"DEVONthink 3\" to get name of tag group of (get database with uuid \"{}\")' -s s".format(selectedDbUUID)
cmdList = shlex.split(cmdScript)
cmdResult = subprocess.check_output(cmdList)
tagList = ast.literal_eval(
"[" + cmdResult[1:-2].decode("UTF8") + "]")

selectedDbUUID = os.getenv('selectedDbUUID', "")
result = {"items": []}
for tag in tagList:
result["items"].append({
"title": tag,
"subtitle": "Press Enter to list all files with this tag",
# "arg": tag,
"variables": {"selectedTag": tag, "selectedDbUUID": selectedDbUUID}
})

if selectedDbUUID == '':
getAllUUIDs = """'set dbUUIDs to {}
tell application "DEVONthink 3"
set allDb to every database
repeat with theDb in allDb
set end of dbUUIDs to (get uuid of theDb)
end repeat
end tell
get dbUUIDs'"""
proc = subprocess.Popen("osascript -e " + getAllUUIDs.strip(),
stdout=subprocess.PIPE, shell=True)
(out, err) = proc.communicate()
DbUUIDs = out.decode('utf-8').strip().split(', ')
for db_uuid in DbUUIDs:
dbresult = runForCertainDB(db_uuid)
result['items'].extend(dbresult)

else:
dbresult = runForCertainDB(selectedDbUUID)
result['items'].extend(dbresult)


if result['items']:
print(json.dumps(result))
Expand Down