$link URL Encoding?

I’ve noticed that when using $link in AppleScript, the entire URL is encoded, and not each individual component on the query string. This has the undesirable effect of encoding the “&” that separate query parameters. This is breaking links in my particular use case, saving a link to an O365 webmail message link in the note of an OmniFocus task while using “Hook to New OmniFocus.”

What I’m seeing:

What I’m expecting:

Is this the expected behavior is there another way I should be approaching this? The hook itself works fine (without encoding), just the link written to the OmniFocus note is broken. Thanks in advance!

To help anyone that stumbles across this in the future, I solved this by using $user_link instead of $link. Here’s a modified version of the OmniFocus New Item AppleScript with working links in the note section:

tell application "OmniFocus"
	tell first document
		-- remove extraneous text from URL
		set AppleScript's text item delimiters to {"$$$"}
		-- Use $user_link instead of $link to avoid URL encoding
		-- set srcURL to text item 1 of "$link"
		set srcURL to text item 1 of "$user_link"
		-- Create a new task and note
		set myTask to make new inbox task with properties {name:"$title", note:"$title"}
		-- hyperlink-ify the note
		set value of attribute named "link" of style of paragraph 1 of note of myTask to srcURL
		set taskID to "omnifocus:///task/" & (id of myTask)
		-- open task
		GetURL taskID
		-- return URL of task for Hook to link with source item
		get taskID
	end tell
end tell

As an aside, is there a list of Hook $ variables available somewhere?

Sorry for the delay in responding. Just to let you know, we’re working on this one. I’ll publish the list of $variables

Fantastic! Thank you for all you are doing!

1 Like