2Do Hook to New

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
1 Like

Super! I’ve added a link to it from the 2Do entry of the linkable apps page.

1 Like

I think $user_link is undocumented — is it OK to use it?

Unless it’s intentional it would be really useful to have the usable placeholders documented.

Yes, you can use $user_link. It is the url of the document.

Also, we will document it in our help pages.

1 Like

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.

1 Like

I am glad it works.

Thank you for your kind words! It means a lot to us.

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?

CleanShot 2023-12-01 at 09.57.18@2x

Sorry about this issue.

Could you please copy the link of this todo task by invoking Hookmark window on it and post it here?

Also invoking Hookmark window on the originating webpage and copy its link from this window and post it here.

Thank you

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

Link to Outlook messaged when opened in Outlook - [Check in](hook ://outlook/160116)

Link to the 2Do task when opened in Outlook - [Check in](twodo ://x-callback-url/showTask?uid=0f201c15e47347bc9adee36a23d3ff83)

Link when opening task from 2Do - [Update the ROPA for Emma G](twodo ://x-callback-url/showTask?uid=71b3ac7c2f754756ad5dd8882702e873)

(Ive manually added a space to the URLs to stop them being formatted as a hyperlink.)

Thank you for the info.

If renaming can change the uid, then Hookmark links will be lost.

I just tried it and so far the url is still the same as the one before renaming. I will check it later.

Thank you

I don’t suppose you ever had chance to review this did you? Its still losing the Hook after a few days.

Sorry about this, @bishblaize .

I still have no luck to reproduce the problem. I have quite a few renamed 2Do tasks long time ago and they all look good.

I am wondering what could trigger that change. I am using Setapp version.

If renaming a task can change task’s uid, we might need contact 2DO developer. I wish I can reproduce the problem.

If you click the 2Do link in the above window, does it open a 2Do task?

Thank you

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.

Thanks for the help on this

Thank you for the info, @bishblaize .

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”?

Thank you