Apple script to add tagged items to todoist

yes I do.

macOS Catalina 10.15.4

I just inserted

open location "https://duckduckgo.com"

to test another link, same behaviour. if I copy both links to the script editor and run them there it works just like intended

And what about this script? Does this work?

on performSmartRule(theRecords)
	open location "https://duckduckgo.com"
end performSmartRule

no (unsurprisingly) not.

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.

You could check System Preferences > Security > Automation > DEVONthink 3.app and whether anything is disabled.

image
seems to be ok…

Does it work after booting the machine in safe mode by pressing the Shift key during startup?

I just get the group selector when running this smart rule.

Running the line in Script Editor opens the URL in my default browser as expected.

on performSmartRule(theRecords)
	tell application "System Events" to open location "https://duckduckgo.com"
end performSmartRule

Opens the URL in the default browser.

Do you use the public release or the latest build?

It was build 11.
Just updated to build 12 and it’s working as expected.

First of all Thank you for the help!
this did the trick:

final script number one:

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)
		tell application "System Events" to open location theURL
		
		tell application "System Events"
			delay 0.3
			keystroke return
			delay 0.3
		end tell
	end repeat
end performSmartRule

@BillW this should work with Omnifocus, too. you would just need to replace the todoist link with “omnifocus:///add?name=” - please note: the link might not be formatted correctly in Omnifocus, but as I’m not a user, I can’t test this. maybe you need to add the “note” parameter to the called link and paste “the_reference” there…

as I mentioned here I already installed the CLI tool for todoist.
A few trial and errors and I got it working now and the addtask window won’t appear, it just happens in the background.
my script looks like this:

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
		end tell
		
		do shell script "$HOME/path/to/the/script/scripts/addSubjectWithLink.sh " & "\"" & this_subject & "\" \"" & the_reference & "\""
		
	end repeat
end performSmartRule

and the shell script I run:

#!/bin/bash
/usr/local/bin/todoist add "[$1]($2)"

I’d be happy to help if someone else needs this.

You’re welcome.
Note the next release will forward unknown URLs, so the

open location "https://duckduckgo.com"

would work too.

great!

do you have any estimate, when the next release will be published?

I’m also wondering, how the “on tagging” trigger will work. E.g. if I add an item on the iPhone with DTTG and add the #todo tag there, will this also be triggered after sync?

And is it possible to force a smart rule to only once on an item? is this what the cancel step does? I did not find anything in the manual.

We don’t publish release dates but it will be soon.

I’m also wondering, how the “on tagging” trigger will work. E.g. if I add an item on the iPhone with DTTG and add the #todo tag there, will this also be triggered after sync?

A file tagged in DEVONthink To Go will not trigger an On Tagging event. It could be processed after an After Synchronization event.

And is it possible to force a smart rule to only once on an item? is this what the cancel step does? I did not find anything in the manual.

No. Just like folder actions, files can be processed more than once. That’s why we advocate moving the files or making a change so they’re no longer matched by the smart rule.

1 Like

Thanks for the details!

small addition to this:
I noticed an issue with “$” signs in the urls to the DEVONthink items. the shell script “lost” them in the links and they did not work correctly. I saw these kind of links with some imported E-Mails.

I adapted the script to resolve this, the updated script looks like this (it simply escapes the $ signs:

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
		end tell
		
		set the_new_reference to findAndReplaceInText(the_reference, "$", "\\$")
		
		do shell script "/$HOME/path/to/the/script/scripts/addSubjectWithLink.sh " & "\"" & this_subject & "\" \"" & the_new_reference & "\""
		
	end repeat
end performSmartRule



on findAndReplaceInText(theText, theSearchString, theReplacementString)
	set AppleScript's text item delimiters to theSearchString
	set theTextItems to every text item of theText
	set AppleScript's text item delimiters to theReplacementString
	set theText to theTextItems as string
	set AppleScript's text item delimiters to ""
	return theText
end findAndReplaceInText
1 Like

I need some help troubleshooting, please. The shell script works from the command line:

~/Scripts/addSubjectWithLink.sh Test https://google.com

creates a task in the Todoist inbox linked to Google.

The Smart Rule finds the correctly tagged items, but when run–nothing happens. No error, nothing.

I copied pasted your script above and then fixed the line to read:

do shell script "$HOME/Scripts/addSubjectWithLink.sh " & "\"" & this_subject & "\" \"" & the_new_reference & "\""

Does it work if you use the full path instead of $HOME? In addition, depending on the name of the items you might have to use quoted form of, e.g.

do shell script "/Users/YourUsername/Scripts/addSubjectWithLink.sh " & quoted form of this_subject & " " & quoted form of the_new_reference
1 Like

Works!! Thanks so much for the help.

1 Like

I get the task created in Todoist but it just has the title of the note and the link doesn’t show up. I copied the final one version. Do I need to make edits to the script? TIA!

are you sure that the link is not in the task?
The title of the note shoud be a clickable link in todoist.

If not, make sure that the shell script contains the following content: