i have an apple script, which I used to add E-Mails to todoist.
I created an “message-id” link to the original message and the subject as displayed text e.g. “subject”.
I triggered this manually. Now I adapted the script, to create a link to the DEVONthink item. creating the link works and I verified it using a display dialoge action, copied the “todoist://addtask?..” link to safari and the task was added like i expected.
The problem I have is, that I can’t automate this within the script. In the Mail script, I simply called an “open location” step with the link as parameter, but when I execute this script in devonthink, I just hear this warning sound from macOS and nothing happens. When I comment out the open location step, and insert the display dialoge step, it works…
Second part of the question: I’d like to automate this based on a tag. Every Item, which receives the tag “#todo” should be added to todoist. I’m not sure, which trigger to use - so when to execute this script, because I dont want to add the same item five times I just want to add it if the tag was assigned newly to this item.
I could create a shortcut on iOS to do this, too but i think thats more complicated than on the mac…
Thank you!
on performSmartRule(theRecords)
tell application id "DNtp"
repeat with theRecord in theRecords
set this_subject to (name of theRecord) as Unicode text
set the_reference to (the reference URL of theRecord) as string
set link_text to "[" & (this_subject) & "](" & (the_reference) & ")"
set encoded_task to do shell script "/usr/bin/python -c 'import sys, urllib; print urllib.quote(sys.argv[1])' " & quoted form of link_text
t
open location "todoist://addtask?content=" & (encoded_task)
tell application "System Events"
delay 0.3
keystroke return
delay 0.3
end tell
end repeat
end tell
end performSmartRule
As smart rule scripts are executed in the background (and sometimes asynchronously), scripting the user interface or using system events in smart rule scripts is discouraged. How does the actual URL of the open location command look like? Maybe it’s an invalid URL.
The url is valid, as I said I debugged this by just adding a dialogue and displayed the url (this worked) and then I copied the url, pasted it into a new safari tab and the add task interface of todoist started.
kind of a workaround, the “addtask” url of todoist actually opens a quick entry menu, where the name of the task will be inserted. then normally I’d need to press enter to confirm the task. but as I want to automate this, the task entry window should just appear quickly and then disappear without the need to press any button / key.
open location has to be performed outside the tell application id "DNtp" block:
on performSmartRule(theRecords)
repeat with theRecord in theRecords
tell application id "DNtp"
set this_subject to (name of theRecord) as Unicode text
set the_reference to (the reference URL of theRecord) as string
set link_text to "[" & (this_subject) & "](" & (the_reference) & ")"
end tell
set encoded_task to do shell script "/usr/bin/python -c 'import sys, urllib; print urllib.quote(sys.argv[1])' " & quoted form of link_text
set theURL to "todoist://addtask?content=" & (encoded_task)
open location theURL
tell application "System Events"
delay 0.3
keystroke return
delay 0.3
end tell
end repeat
end performSmartRule
NOTE:
The next release won’t require this workaround anymore.
I think there must be something wrong with permissions / security settings… can you tell me what has to be enabled?
DEVONthink is already enabled in the Accessibility settings.