Getting "Copy as link" from Applescript?

Hi
I’ve been trying to get the link for each flagged task but when I try to get id of task, it just gives me a large number and not at all the alphanumeric code I get if I right click in omnifocus and “Copy as Link”. This number doesn’t allow me to open the task with the URL like the Link does either.

Any ideas?

on run {}
tell application “OmniFocus”
tell default document
set flaggedTasks to name of (every flattened task whose flagged is true and completed is false)

  	repeat with a from 1 to length of flaggedTasks
  		
  		set currentTask to item a of flaggedTasks
  		
  		set taskID to id of currentTask
  		
  		GetURL ("omnifocus:///task/" & taskID)
  		
  	end repeat
  end tell

end tell
end run

Your variable flaggedTasks is a list of the name of each task. It’s not the tasks themselves. Try this:

on run {}
tell application "OmniFocus"
tell default document
set flaggedTasks to every flattened task whose flagged is true and completed is false

		repeat with a from 1 to length of flaggedTasks

			set currentTask to item a of flaggedTasks

			set taskID to id of currentTask

			GetURL ("omnifocus:///task/" & taskID)

		end repeat
	end tell
end tell
end run
2 Likes

oh my god, I can’t believe I didn’t see that I put it as name! Thank you so much!

2 Likes

A more compact version

on run {}
tell application "OmniFocus" to tell default document
set flaggedTasks to every flattened task whose flagged is true and completed is false

	repeat with currentTask in flaggedTasks

		set taskID to id of currentTask
		GetURL ("omnifocus:///task/" & taskID)

	end repeat
end tell
end run


JJW

1 Like