I was writing a script that could be used as a PDF Service to add a corresponding task in OmniFocus. The main difference from other similar scripts is that it shows up in Quick Entry so I can add more information to the task.
I got most of the way fine, but ran into some issues with OmniFocus's selection model. Is there a better way to get from an item to a leaf?
This is what I've got right now, with a comment showing where I tried something that seemed more reasonable (but which didn't work):
I got most of the way fine, but ran into some issues with OmniFocus's selection model. Is there a better way to get from an item to a leaf?
This is what I've got right now, with a comment showing where I tried something that seemed more reasonable (but which didn't work):
Code:
on open _items local _item, _name, _task repeat with _item in (_items as list) tell application "System Events" set _name to _item's name get _item's name extension if (result ≠ "") then -- strip extension set _name to (characters 1 thru ((count _name's characters) - (count result's characters) - 1) of _name) as string end if end tell tell application "OmniFocus" tell front document's quick entry open set _task to (make inbox task with properties {name:_name}) tell _task's note to make new file attachment with properties ¬ {file name:_item's POSIX path, embedded:true} get _task's id -- get leaves whose id is result -- error "Can’t get id whose it = \"m75YwCmFP4l\". Access not allowed." number -1723 repeat with _leaf in leaves if _leaf's id is result then select _leaf exit repeat end if end repeat end tell activate end tell end repeat end open