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
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.
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
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