The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniFocus > OmniFocus Extras
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
AppleScript question Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
AppleScript has many nuances that even the most experienced scripter can be caught out by using one term incorrectly. I've been scripting for over 10 years and it can be still be trial and error (or reading a lot of other people's scripts with an application I haven't scripted before). However, if you can get past many of its nuances, AppleScript is a very powerful language. OmniGroup's AppleScript support of their apps is excellent too.

You need to capture the project that the items in the inbox are going to be assigned to first. Following your example, you have a folder in your library called "Work", with a sub-folder called "Operations & Finance" and a project in that folder called "AP, AR, Finance"

In order to capture the project, you must target the OmniFocus document, not its contents, which is how the context is captured at the beginning of the script too. So long as the hierarchy of this folder structure is going to remain the same this can be hard-coded into the script, otherwise you will have to follow whpalmer4's advice and step through the contents of the library looking for a matching name (unfortunately, I don't have time to look at scripting that). To hard-code the hierarchy structure into the script add the following line of script below the "set theContext to..." line:

set theProject to the project "AP, AR, Finance" of folder "Operations & Finance" of folder "Work"

Next, you need to assign the project to the selected Inbox item later in the script. Replace the following line of code:

set name of parent task of anItem to "AP, AR, Finance"

with this line of code:

set assigned container of anItem of theSelectedItems to theProject

That will get what you want to achieve. I've included the entire script below:

Code:
tell application "OmniFocus"
	tell front document
		set theContext to the context "Online" of context "Mac"
		set theProject to the project "AP, AR, Finance" of folder "Operations & Finance" of folder "Work"
		tell content of document window 1 -- (first document window whose index is 1)
			set theSelectedItems to value of every selected tree
			if ((count of theSelectedItems) < 1) then
				display alert "You must first select an item to complete." as warning
				return
			end if
			repeat with anItem in theSelectedItems
				set assigned container of anItem of theSelectedItems to theProject
				set context of anItem to theContext
				set due date of anItem to current date
			end repeat
		end tell
	end tell
end tell
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Email/iOS/Mailtags Question... more GTD question more than OmniFocus filmgeek Applying OmniFocus 3 2010-11-06 06:00 AM
Applescript question for Omni Group pvonk OmniFocus 1 for Mac 3 2009-10-06 09:16 AM
Dead stoopid AppleScript question: finding the tell target jporten OmniFocus Extras 1 2009-03-19 10:10 AM
Omniweb Applescript Question russophile OmniWeb General 4 2008-03-14 12:56 PM


All times are GMT -8. The time now is 04:30 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.