Embed file in OmniFocus Applescript help request

I’m trying to write an Applescript to embed the currently selected file in Finder in OmniFocus, could somebody please help me to make it work?

At the moment it gives me the following error: “OmniFocus got an error: The file “logo.jpg” couldn’t be opened because you don’t have permission to view it.” and I don’t know what I need to do to make it work.

Please find the script below.

 tell application "Finder"
    	set this_item to get selection
    	set myPath to POSIX path of (this_item as text)
    end tell

tell application "OmniFocus"
	tell default document
		set newTask to make new inbox task with properties {name:"Test"}
		tell the note of newTask to make new file attachment with properties {file name:myPath, embedded:true}
	end tell
end tell

Any help would be appreciated.

This change should fix it, I believe (leaving out “the”).

tell note of newTask to make new file attachment with properties {file name:myPath, embedded:true}`

That’s what it did over here too. I then granted OmniFocus full disk access - no change. Tried to use an alias instead of POSIX path - it first didn’t work but somehow did in the end. After using an alias worked I tried POSIX path again and now this also worked. No idea what’s going on.

Anyway if you want to edit your embedded attachments you’ll have to change the file’s permissions How do I automatically unlock locked photo attachments?


tell application "Finder"
	try
		set this_item to get selection
		set myPath to POSIX path of (this_item as text)
		
		#set theSelection to selection
		#if theSelection = {} then error "No selection"
		#set myPath to item 1 of theSelection as alias
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "Finder" message error_message as warning
		return
	end try
end tell

tell application "OmniFocus"
	try
		tell default document
			set newTask to make new inbox task with properties {name:"Test"}
			tell the note of newTask to make new file attachment with properties {file name:myPath, embedded:true}
		end tell
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "OmniFocus" message error_message as warning
		return
	end try
end tell

Thank you all for your help.

This seems to work consistently for me:

tell application "Finder"
	repeat with f in (get selection)
		tell application "OmniFocus"
			tell the first document
				set NewTask to make new inbox task with properties {name:"file_name"}
				tell the note of NewTask
					make new file attachment with properties {file name:f as alias, embedded:true}
				end tell
				activate
			end tell
		end tell
	end repeat
end tell
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.