Now you can create new tasks in 2Do that are Hooked!
set encodedTitle to do shell script "python -c \"import urllib, sys; print (urllib.quote(sys.argv[1]))\" " & quoted form of "$title"
set encodedTag to do shell script "python -c \"import urllib, sys; print (urllib.quote(sys.argv[1]))\" " & quoted form of "from:Hook"
set linkToParent to "$user_link"
set xCallbackUrl to "twodo://x-callback-url/add?task=" & encodedTitle & "&type=0&tags=" & encodedTag & "&action=url:" & linkToParent & "&saveInClipboard=1&edit=1"
-- presere clipboard as 2Do will put the UID there
set originalClipboard to the clipboard
set the clipboard to ""
open location xCallbackUrl
delay 0.2
set theUID to the clipboard
set the clipboard to originalClipboard
return "twodo://x-callback-url/showTask?uid=" & theUID
I had a go at this script but it doesn’t work for a Hook to New. Regular Hooks work fine in 2do and the 2Do URL scheme works normally, so I guess something has changed in the last 2 years that means the original script above is no longer functional. Any ideas for where to start?
I remember Apple changed something for Python on macOS.
Here is the new script you can give it a try:
Summary
use framework "Foundation"
use scripting additions
property NSString : a reference to current application's NSString
property NSMutableCharacterSet : a reference to current application's NSMutableCharacterSet
set charset to NSMutableCharacterSet's URLQueryAllowedCharacterSet's mutableCopyWithZone:(missing value)
charset's removeCharactersInString:"&=?"
set theString to NSString's stringWithString:"$title"
set encodedTitle to theString's stringByAddingPercentEncodingWithAllowedCharacters:charset
set encodedTag to "from:Hook"
set linkToParent to "$user_link"
set theString to NSString's stringWithString: linkToParent
set linkToParent to theString's stringByAddingPercentEncodingWithAllowedCharacters:charset
set xCallbackUrl to "twodo://x-callback-url/add?task=" & encodedTitle & "&type=0&tags=" & encodedTag & "&action=url:" & linkToParent & "&saveInClipboard=1&edit=1"
-- presere clipboard as 2Do will put the UID there
set originalClipboard to the clipboard
set the clipboard to ""
set myScript to "open " & quoted form of xCallbackUrl
do shell script myScript
delay 0.2
set theUID to the clipboard
set the clipboard to originalClipboard
return "twodo://x-callback-url/showTask?uid=" & theUID
Ah, wonderful, that worked first time. Thank you so much.
Its funny, I was fishing around for a new task manager and I realised that literally the first thing on my list of requirements was whether it worked with Hookmarks or not. Really has become an essential part of my workflow I end up feeling lost when I can’t use some bit of it.
Sorry for returning to this, but the behaviour of this seems to be a bit odd. I find that Hooks are disappearing from the tasks.
When I create a new hooked task, it works fine at first. However at some point down the line it stops showing the bookmark when I invoke Hook. I can see that the Hook tag is still on the task so I know its the right one. It shows up if I search for it manually in my Hook bookmarks. If I go to the originating webpage and invoke Hookmarks, it shows it being linked to the task. It just won’t show it if I invoke Hookmarks directly from 2Do.
I then noticed that 2Do has a URL field you can put links in (attached), and for some reason the originating URL is ending up there. So I can access it, but not via the Hookmarks gui. Really not sure why this is happening, anyone have any thoughts?
Thanks for the reply. I wonder whether its to do with renaming the task? I end up renaming most tasks. I’ve tried renaming a 2Do task and it doesn’t break immediately, but still, it doesnt seem to have kept track with the change eventually.
In this case I renamed it from Check In to Update ROPA for Emma G
If I invoke Hookmarks from Outlook, then it shows the hooked 2Do task at the bottom with the original name. If I key down and copy that version of the task, the link is different
Yeah just tried it. Even if the link is lost when you look at it in 2Do, its still there in Outlook and clicking the link will open up 2Do at the correct task.
One other point, I found what appears to be a link the original 2Do tasks in the Hookmarks history. However clicking it no longer works. It opens 2Do, but just at whatever the last viewed task was.
So the link “twodo ://x-callback-url/showTask?uid=0f201c15e47347bc9adee36a23d3ff83” can open “Update the ROPA for Emma G” task correctly.
If you open the link “twodo ://x-callback-url/showTask?uid=71b3ac7c2f754756ad5dd8882702e873” using Spotlight search(or paste it somethere so you can click on it), will it open the correct 2Do task? If yes, does it open the same 2Do task as “twodo ://x-callback-url/showTask?uid=0f201c15e47347bc9adee36a23d3ff83”?