Modifying the OmniFocus "Link to New" script

Hi, Guys.

I’m trying to modify the OmniFocus “Link to New” script to create a new task in the quick entry window instead of activating OmniFocus and showing the Inbox. Just looking to make capturing a little quicker for myself.

Here’s what I have so far (stolen from Ben Waldie)…

tell application "OmniFocus"

tell application "OmniFocus"
	tell quick entry
		
		-- Create a new task and note.
		make new inbox task with properties {name:"$title", note:"$link"}
		
		-- Expand the task to display the note.
		set note expanded of every tree to true
		
		-- Open the task
		open
	end tell
end tell
end tell

What do I put instead of “$title” so that the titled link goes in the note instead of the full URL?

Thanks!

I don’t expect this to work as is, but to point you possibly the right direction does something similar to this work?

set myNote to “$title”
set myNote‘s style's attribute "link"'s value to "$link" as text
make new inbox task with properties {name:"$title", note:myNote}

I’m not sure I understand what’s going on in your example. Sorry.

My script works, except neither “$title” nor “$link” produce a working, clickable link in the notes field.

“$title” gives me

image

and “$link” gives me

image

I just want to know what I need to put so that I get a titled, clickable link in the note field.

Here’s the full script…

 # 1. copy as link

tell application "System Events"
	# Get the frontmost app's *process* object.
	set frontAppProcess to first application process whose frontmost is true
end tell

# Tell the *process* to count its windows and return its front window's name.

tell frontAppProcess
	if (count of windows) > 0 then
		set documentName to name of front window
	end if
end tell

tell application "System Events"
	set documentLink to "LINK" --URL of front document as text
end tell


# 2. Create New Task in Quick Entry Window

tell application "OmniFocus"
	tell quick entry
		-- Create a new task and note.
		make new inbox task with properties {name:"$title", note:"$link"}
		
		-- Expand the task to display the note.
		set note expanded of every tree to true
		
		-- Open the task
		open
	end tell
end tell

try this:

tell application "OmniFocus"
	tell quick entry
		-- remove extraneous text from URL
		set AppleScript's text item delimiters to {"$$$"}
		set link to text item 1 of "$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 link
		
		-- Expand the task to display the note.
		set note expanded of every tree to true
		
		-- Open the task
		open
		
		-- return URL of new note for Hook to link with source item
		get "omnifocus:///task/" & (id of myTask)
	end tell
end tell

There’s a few extra things going on here

-- remove extraneous text from URL
$link is the URL with "$$$title-of-the-document-encoded-in-base64 appended to the end of it. You’ll want to remove that second bit

-- hyperlink-ify the note
This is the part you’re actually asking for help with and the solution is courtesy of Amy in this thread from the Omnifocus forums. stevelw was on the right track with setting the text’s link attribute.

-- return URL of new note for Hook to link with source item
To automatically link the new note with the source document, you have to return the URL of the new item. Hook will use that to link the two together.

I hope this works for you!

Would you please be to kind as to describe what your exact workflow is? Are you integrating OF with Hook?

Thanks!

Sure. Here’s a rundown of what I’m attempting.

I want to get Hook to create a new OmniFocus task, but using the Quick Entry window instead of activating OmniFocus and opening the Inbox itself. I also want Hook to paste the title of the current item into the task field and paste a titled link to the current item into the notes field.

This script would replace Hook’s default “Create New” script since this is my preferred way of entering tasks.

Summarized thusly:

  1. Open Quick Entry

  2. Paste Title into Task field

  3. Paste titled link into Notes field

  4. Manually select project and/or tag(s)

  5. Finalize and dismiss with

I can do all of these manually, but I would feel much more productive and clever if I could simply trigger a script to do it for me.

Thoughts?

@grahamb

That totally works! Thanks.

The only issue is that my script is now producing an OmniFocus dialog saying the operation could not be completed, though everything is just fine. I’ll take some time to sort out the problem and post the entire script once it’s not doing anything weird. Thanks so much!

1 Like

I’ve found the problem.

After the New Document script runs, Hook automatically opens the new note, but because the script finishes before the note exists, Omnifocus fails to open it and throws up an alert dialog.

I don’t think there’s any way to use Omnifocus’ Quick Entry window without running into this issue at present, but I’ll look into it.

Ah. That makes sense.

I’ll try the whole operation without using the “new note” function.

Might take me a couple days to get to it.

Thanks!