A better script for Things

I just bought Hook as part of Winterfest 2019. I’m still grokking its value but an obvious thing it can do is send a URL from my browser to Things as a TODO. However, …

The new todo in Things ends up with the page title as the name. That’s okay but not ideal because page titles are often crappy, for example:

Cognitive Productivity with… by Luc P. Beaudoin [PDF/iPad/Kindle]

It would be neat if Hook could be set, for a given app, to prompt to edit the title.

Then again, although this is a page in a browser the URL doesn’t end up in the Things todo. You might argue that’s okay because Hook knows what the URL is. However, I use Things on Mac, iPad, and iPhone. If the todo at least had the URL it would be a lot more useful when I’m mobile.

Lastly, it would be nice to add an excerpt (maybe the 1st paragraph) from the page to the notes of the todo. Perhaps that’s overdoing it but I can see it being a useful reminder.

I’ve had a quick look at the scripts in Hook. I’m not really au fait with AppleScript although I can figure my way around it. I found another script using an $encoded_link specifier which I used as:

set notes of new_todo to "$encoded_link"

This technically worked in that I got the page URL but I also got a load of random characters stuck on the end:

Things Support

It’s not harmful in this case (I can load the page) but I’ve not seen this $$$ protocol before and I’m not sure it’s safe to encode any link in this way. I guessed using $link instead of $encoded_link but that didn’t seem to make a difference.

Is there another approach?

I’m guessing the excerpt may not be possible because there’s no way to ask for it from a random app.

Matt

welcome to the Hook Productivity Forum @taonmatt.

As you discovered, currently the “Link to New” scripting framework is not setup with an option to prompt for the title. The reason we didn’t prompt for title by default was to speed up “Link to New” , making it one ballistic “combo” action (create item, name it, store it, link it, and optionally tag it (currently only files can be tagged by Hook)).

For comparison: the OmniFocus “new document” script currently adds the URL in the notes field. I think it would make sense for Hook’s default Things’ “new document” script to do the same thing.

Something like this is in our longer road map for Hook (and I think we did this for gStudy and nStudy at Simon Fraser University ( “Learning Kit” project)), and I think it’s come up in the forum before, namely an option to append selected text to a notes document. Getting this right generically requires some thought and would require an update to the script framework. It would be handy for creating “notes documents” about one’s readings (which in my first book, and at SFU, I referred to as “meta-docs”), and be IMO very useful for educational purposes.

You could perhaps try this. You can choose a title for your Things task and the URL is added as a note:

tell application id "com.culturedcode.ThingsMac"
            set new_todo to make new to do
            set theTitle to display dialog "Your title?" default answer ""    with icon note buttons {"Cancel", "OK"} default button "OK"
            set name of new_todo to text returned of theTitle
            set AppleScript's text item delimiters to "$$$"
            set theTextItems to every text item of "$encoded_link"
            set AppleScript's text item delimiters to ""
            set myLink to the first item of theTextItems
            set notes of new_todo to myLink
            set todo_url to "things:///show?id=" & id of new_todo
            edit new_todo
            activate
            end tell
            todo_url

But as Luc already said, this is not quite in the sense of Hook. And, only the Things note is named differently, not the entry in Hook.
Perhaps it helps…

while we’re on the topic: I can’t recall if I mentioned this previously on the forum, but in the future, Hook should dynamically update the title associated with a given object (URI) that it has stored in its database and that it presents to users in the Hook popup window. I.e., when Hook is invoked in the context of a non-file item (such as web page, a Things task, or Omnifocus task) Hook would compare the title it gets from the app with what is stored in its database. If they don’t match, Hook would update the title in the database.

Hook already updates its representation of file names, so I don’t think we need to expose a preference for this for non-file objects (maybe an advanced (command-line) preference to disable it, if someone sees a need not to do this?).

1 Like

@cremoer’s script seems to do most of what you’re asking for, except it should use “$link” instead of “$encoded_link”

[$encoded link] technically worked in that I got the page URL but I also got a load of random characters stuck on the end:

“$encoded_link” is the percent encoded source URL, and the base 64 encoded source title, separated with “$$$” It includes the “$$$” and base64 title because of legacy reasons. It is percent encoded so that it can be used as a variable in an x-callback-url.

In your case you don’t want it to be percent encoded, so you should use “$link” which is the same thing without the percent encoding.

And to remove the base64 encoded title or $$$, you need something like this, from @cremoer’s script

set AppleScript's text item delimiters to "$$$"
set theTextItems to every text item of "$encoded_link"
set AppleScript's text item delimiters to ""
set myLink to the first item of theTextItems

It would be neat if Hook could be set, for a given app, to prompt to edit the title.

If you hold down option (⌥) in the title menu, or press ^⌥⌘N, you can “Link to New As…” which is just like Link to New except it prompts you for the title of the new item. Try it with this script:

tell application id "com.culturedcode.ThingsMac"
	set new_todo to make new to do
	set name of new_todo to "$title"
	set AppleScript's text item delimiters to "$$$"
	set theTextItems to every text item of "$link"
	set AppleScript's text item delimiters to ""
	set myLink to the first item of theTextItems
	set notes of new_todo to myLink
	set todo_url to "things:///show?id=" & id of new_todo
	edit new_todo
	activate
end tell
todo_url

First of all, many thanks for your helpful responses. It’s great to be interacting with people who know the product really well and care about it. I guess it’s one of those kinds of tools!

I thought I had tried $link rather than $encoded_link and gotten the same result, possibly I was not careful enough, does Hook do any caching of scripts?

I will try it again.

m@

Ah, that’s very useful to know. Thank you!

m@

1 Like

Hi Matt

It is the % encoded URL, where the # for example becomes %23 , so it is the first part of the link. On the right of the $$$ is the base 64 encoded title of the website. This is the same with $link and $encoded_link. So there are 2 different encodings :grinning:

I thought I had tried $link rather than $encoded_link and gotten the same result, possibly I was not careful enough, does Hook do any caching of scripts?

Hook doesn’t cache scripts, although I find that sometimes I slip up and edit a script but don’t press “Save” so it runs the old version when I try to test it

$link and $encoded_link will only differ if the URL contains characters which aren’t allowed in a URL query

To clarify something, all valid URLs are percent encoded, but I believe that $encoded_link is double encoded, so that the whole URL itself can be passed as a x-callback query variable.

1 Like