Help with Applescript to paste URL to notes field

I am trying to decode the difference between using an Applescript to paste a URL and using the keyboard. I have a URL on the clipboard (copy as URL from a Curio figure). I need to paste this in to the notes field of an OmniFocus task. With an Applescript of this

	set the note of theTask to the clipboard

I get this

  • curio:///Users/jjw/Documents/Zen-Tao/GTD.curio?ideaspace=04E729BD-CF57-4B11-9991-7C821E62AD57&figure=9C0EABBD-6169-42C3-997A-A27E1F8964B0

With a standard command-v from the keyboard to paste to the notes field, I get this as a hyperlink content

  • Curio project “GTD” > “RCEU 18 Confirm - Silanes”

I know about system events to do command-v. However, this is not going to work to put the clipboard in to the notes field AFAIK.

How do I force the second format?

Why do I care? Don’t both work?

Not really.

The former format is based on a location specific within the document. The latter will find the figure in Curio even when I will move it to a different location spot. Also, the second format is more “human readable”.

–
JJW

1 Like

Here is the reference you’re looking for

https://developer.apple.com/library/content/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_cmds.html#//apple_ref/doc/uid/TP40000983-CH216-SW26
https://developer.apple.com/library/content/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_cmds.html#//apple_ref/doc/uid/TP40000983-CH216-SW28

I think you need to use clipboard info to find out if the type you want is on the clipboard and access the type directly using as class

The issue is a bit more complicated. It seems, the initial problem I noted is an oddity that is irreproducible. The only real desire is to cast the note field in to a human readable form. The difference is likely boils down to how these two options works

  • set theClip to the clipboard
    set the note of theTask to the clip

  • set theClip to the clipboard
    … somehow activate the note field of a task as though it is a text edit document …
    tell application “System Events” to keystroke “v” using {command down}

The first approach puts the url string in the note field as curio://… whereas the second approach recasts the clipboard contents to a human readable form <a href=“curio://…”.>title</a> format.

This next step is somewhat above my time constraints at the moment.

Thanks.

–
JJW

I don’t use Curio myself but I downloaded a trial to test this code. It sets the note of the first selected task to a link that is stored in the clipboard, in a human readable form.

Tell me if you have any suggestions or questions.

use framework "Foundation"
use scripting additions

on run
	set recData to getURLData()
	set oTask to item 1 of getSelectedTasks()
	setNameAndURL(oTask, (theName of recData), (theURL of recData))
end run

on getURLData()
	set strURL to the clipboard as text
	set ca to current application
	set pstBoard to ca's NSPasteboard's generalPasteboard
	set nsURLName to pstBoard's stringForType:"public.url-name"
	set strName to nsURLName as text
	return {theName:strName, theURL:strURL}
end getURLData

on getSelectedTasks()
	tell application "OmniFocus"
		set oDoc to front document
		set oWin to front document window of oDoc
		return (get value of selected trees of content of oWin)
	end tell
end getSelectedTasks

on setNameAndURL(oTask, strName, strURL)
	using terms from application "OmniFocus"
		set note of oTask to strName
		set value of attribute "link" of style of paragraph 1 of note of oTask to strURL
	end using terms from
end setNameAndURL
3 Likes

Wow. I see the implementation of the application’s NSPasteboard. Well over my head here, but it is what I thought. I would have to recast the clipboard to a proper URL format using both pieces of information. My attempts through pbcopy and pbpaste where also for naught I might add.

I will implement this in a modification of my current script.

Thank you!!!

–
JJW

1 Like

Oh, my, this is so cool @unlocked2412! You are one of my scripting heroes.

1 Like

Here is a link to the newest version of the script to link Curio <-> OmniFocus with URLs.

Thank you again to @unlocked2412 for decoding the method. The new version handles various user mistakes (no selection) and allows to select the Project from the main or sidebar. It also replaces or appends text in the note field as needed.

Enjoy!

–
JJW

1 Like