A very nice poster, McUsrII, put up an attempt to help me with the following AppleScript:
property pEmbedFile : true (* if true, file will be embedded
if false, file will be linked *)
property pUseQuickEntry : false (* if true, Quick Entry window used and left open
if false, actions added directly to Inbox *)
property pDefaultProject : "Incoming"
property pDefaultContext : "@Mac"
on adding folder items to this_folder after receiving added_items
try
repeat with i from 1 to number of items in added_items
set this_item to item i of added_items
tell application "Finder" to set file_name to (name of this_item)
tell application "OmniFocus"
set theContext to (first flattened context where its name = pDefaultContext)
set theProject to (first flattened project where its name = pDefaultProject)
if (pUseQuickEntry) then
tell quick entry
open
tell theProject
set NewTask to make new task with properties {name:file_name, context:theContext}
tell the note of NewTask to make new file attachment with properties {file name:this_item, embedded:pEmbedFile}
end tell
activate
end tell
else
tell front document
tell theProject
set NewTask to make new task with properties {name:file_name, context:theContext}
tell the note of NewTask to make new file attachment with properties {file name:this_item, embedded:pEmbedFile}
end tell
end tell
end if
end tell
end repeat
end try
end adding folder items to
It is an attempt to combine the following two scripts:
-- Lovingly crafted by David Sparks, The Omni Group, and Ben Waldie -- macsparky.com
set theDate to current date
set theTask to "Pay Life Insurance"
set theNote to "Lovingly Scanned by your Mac on " & (theDate as string)
tell application "OmniFocus"
tell front document
set theContext to first flattened context where its name = "Tech"
set theProject to first flattened project where its name = "Finance"
tell theProject to make new task with properties {name:theTask, note:theNote, context:theContext}
end tell
end tell
And this script:
property pEmbedFile : true (* if true, file will be embedded
if false, file will be linked *)
property pUseQuickEntry : false (* if true, Quick Entry window used and left open
if false, actions added directly to Inbox *)
on adding folder items to this_folder after receiving added_items
try
repeat with i from 1 to number of items in added_items
set this_item to item i of added_items
tell application "Finder" to set file_name to (name of this_item)
tell application "OmniFocus"
if (pUseQuickEntry) then
tell quick entry
open
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:this_item, embedded:pEmbedFile}
end tell
activate
end tell
else
tell front 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:this_item, embedded:pEmbedFile}
end tell
end tell
end if
end tell
end repeat
end try
end adding folder items to
Unfortunately McUsrII’s script to try to combine them didn’t seem to work as a Folder Action. Perhaps I’m screwing something up, I have very very little experience.
I did see one little thing that I should have added in my original request though, the ability for the script/folder action to add a custom default Spotlight Comment to the file after adding it to my OmniFocus database. I’m doing some, by my standards, sophisticated sorting and filing rules with Hazel and asking Hazel to look for a specific Spotlight Comment applied after adding the file to OmniFocus seems to be the only way to assure the Hazel rule isn’t triggered before the Folder Action has a chance to do its thing.
Many Many thanks in advance and to McUsrII for the help and pointers.