OmniFocus add document

Would there be a way to take this Folder action script and modify it to add a default Project and context to the action as well?

Here on David Sparks site he shows how to make an action via applescript with a default project and context:

– 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 here is a Folder Action that automatically adds the file to the inbox of OmniFocus but without a default Project or Context via dave at the OmniGroup:

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

I am trying to accomplish some rather in depth Hazel, Paperless, automatic OCRing mojo and I thought I could simply look at the applescripts and combine them myself, but… Way beyond me. I know someone with some AppleScript chops can do it, probably in an instant.

Many many thanks in advance.

Hello and welcome to MacScripter.

You have posted in the wrong place, you should have posted in the AppleScript/Mac OsX forum, please use the AppleScript tags at the top of the box when you post code.

I have made a little snippet for you, but not tested it.

You have to change the default context and project at the top of the script. :slight_smile:


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

Thanks for the heads up on where to post. And thank you for the attempt at a solution. Unfortunately it isn’t working. Which, in retrospect, is fine as I forgot one rather crucial request to add to the script! I’ve reposted in the appropriate place. http://macscripter.net/viewtopic.php?pid=158114#p158114

Thanks again.