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

 
Need Assistance: AppleScript to Properly File Inbox Task Based on Textual Tag of Name Thread Tools Search this Thread Display Modes
I use the "OmniFocus URI Handler" as a way of getting web pages from Firefox into OmniFocus. Unfortunately, despite the protocol stating it'll accept contexts and projects, it doesn't.

I've been trying to get around that by tacking on a textual tag to the end of the task name, and then I had hoped to create an AppleScript that would assign contexts based on that textual tag.

For example, the OmniFocus URI Handler might write "Task name [@phonecall]", and this AppleScript would take the text tag "@phonecall" in the name and assign the actual context "Phone This" to that.

I was able to splice a few people's scripts together, but it just isn't working, and, moreover, it doesn't seem anywhere near working.

As it stands in its form below, the script's error is that it tells me "can't get context".

Additionally, the three things I'd like the script to do -- that I know that, as currently structured, it can't -- are: (a) be able to go through all tasks currently selected, not just one task at a time; (b) remove the textual tag once the task's been properly assigned; and (c) move the task to one particular folder (named "Miscellaneous") once the proper context is assigned. (Ideally, maybe with certain contexts which always go into a certain different folder, I could figure out how to treat those particular exceptions.)

In any case, if anyone who is knowledgeable about OmniFocus and AppleScript would be of a kind enough mind to offer their help, it would be appreciated. I'm sure such a structure would be useful enough for others to adapt for their own, different purposes.

I know that this is badly structured, messy code, so if you are of a mind to help and want to completely rip this apart, go for it.

Code:
tell application "OmniFocus"
	
	tell front document
		tell document window 1
			set theSelectedItems to selected trees of content
			if ((count of theSelectedItems) < 1) then
				display alert "You must first select a single task." message "Select a single task before running this script." as warning
				return
			end if
			if ((count of theSelectedItems) > 1) then
				display alert "You must select only one task." message "Select a single task before running this script." as warning
				return
			end if
			
		end tell
	end tell
	
	set theDoc to document window 1 of document 1
	
	set theSelectedTask to value of item 1 of theSelectedItems
	if the name of item 1 of theSelectedItems contains "@add2sys" then set context of item 1 of theSelectedItems to context "Add to System" of context "URLs"
	if the name of item 1 of theSelectedItems contains "@blog" then set context of item 1 of theSelectedItems to context "Blog About" of context "URLs"
	if the name of item 1 of theSelectedItems contains "@bm" then set context of item 1 of theSelectedItems to context "Bookmark" of context "URLs"
	if the name of item 1 of theSelectedItems contains "@dl-app" then set context of item 1 of theSelectedItems to context "App" of context "Download" of context "URLs"
	if the name of item 1 of theSelectedItems contains "@job" then set context of item 1 of theSelectedItems to context "Job Listing" of context "URLs"
	if the name of item 1 of theSelectedItems contains "@mail" then set context of item 1 of theSelectedItems to context "Mail to Someone" of context "URLs"
	if the name of item 1 of theSelectedItems contains "@notepad" then set context of item 1 of theSelectedItems to context "Project Notepad" of context "URLs"
	if the name of item 1 of theSelectedItems contains "@optimism" then set context of item 1 of theSelectedItems to context "Optimism" of context "URLs"
	if the name of item 1 of theSelectedItems contains "@parse" then set context of item 1 of theSelectedItems to context "Parse" of context "URLs"
	if the name of item 1 of theSelectedItems contains "@queue" then set context of item 1 of theSelectedItems to context "Queue (Add To)" of context "URLs"
	if the name of item 1 of theSelectedItems contains "@read" then set context of item 1 of theSelectedItems to context "Read This" of context "URLs"
	if the name of item 1 of theSelectedItems contains "@rss" then set context of item 1 of theSelectedItems to context "RSS (Add To)" of context "URLs"
	if the name of item 1 of theSelectedItems contains "@thinkabout" then set context of item 1 of theSelectedItems to context "Think About" of context "URLs"
	if the name of item 1 of theSelectedItems contains "@watch-long" then set context of item 1 of theSelectedItems to context "Long" of context "Watch" of context "URLs"
	if the name of item 1 of theSelectedItems contains "@watch-short" then set context of item 1 of theSelectedItems to context "Short" of context "Watch" of context "URLs"
	
	tell first document window of front document
		set selected view mode identifier to "project"
		tell sidebar
			select inbox
		end tell
	end tell

end tell

Last edited by WCityMike; 2009-10-17 at 04:21 PM..
 
I've rewritten the script to meet your needs and tested it with my own contexts. I've gathered your @ contexts and actual contexts into lists at the beginning of the script with a third list that categorises them into top-level, sub-level and sub-sub-level contexts.

The script then gathers the actual contexts from OmniFocus and then tests the ShortContextList for the selected action in OmniFocus to determine the correct context to apply to it.

Code:
set TopContext to "URLs"
set SubSubContext1 to "Download"
set SubSubContext2 to "Watch"
set ShortContextList to {"@add2sys", "@blog", "@bm", "@dl-app", "@job", "@mail", "@notepad", "@optimism", "@parse", "@queue", "@read", "@rss", "@thinkabout", "@watch-long", "@watch-short"}
set FullContextList to {"Add to System", "Blog About", "Bookmark", "App", "Job Listing", "Mail to Someone", "Project Notepad", "Optimism", "Parse", "Queue (Add To)", "Read This", "RSS (Add To)", "Think About", "Long", "Short"}
set ContextTypeList to {"SubContext", "SubContext", "SubContext", "SubSubContext1", "SubContext", "SubContext", "SubContext", "SubContext", "SubContext", "SubContext", "SubContext", "SubContext", "SubContext", "SubSubContext2", "SubSubContext2"}
set OmniFocusContexts to {}
set i to 1

tell application "OmniFocus"
	tell front document
		-- Capture the top-level, sub-level and sub-sub-level contexts
		repeat with theContext in FullContextList
			if item i of ContextTypeList = "TopContext" then
				set the end of OmniFocusContexts to context TopContext
			else if item i of ContextTypeList = "SubContext" then
				set the end of OmniFocusContexts to context theContext of context TopContext
			else if item i of ContextTypeList = "SubSubContext1" then
				set the end of OmniFocusContexts to context theContext of context SubSubContext1 of context TopContext
			else if item i of ContextTypeList = "SubSubContext2" then
				set the end of OmniFocusContexts to context theContext of context SubSubContext2 of context TopContext
			end if
			set i to i + 1
		end repeat
		
		
		tell content of document window 1
			set theSelectedItems to value of every selected tree
			if ((count of theSelectedItems) < 1) then
				display alert "You must first select a single task." message "Select a single task before running this script." as warning
				return
			end if
			if ((count of theSelectedItems) > 1) then
				display alert "You must select only one task." message "Select a single task before running this script." as warning
				return
			end if
			set i to 1
			-- Test for the short context and apply the correct context to the action
			repeat with anItem in theSelectedItems
				repeat with AShortContext in ShortContextList
					if the name of anItem contains AShortContext then set context of anItem to item i of OmniFocusContexts
					set i to i + 1
				end repeat
			end repeat
		end tell
		
		tell document window 1
			set selected view mode identifier to "project"
			tell sidebar to select inbox
		end tell
		
	end tell
end tell
 
Damon, I can't believe you were kind enough to put this together. I'm ecstatic. Thank you so much -- I can't wait to give this a trial run and get it implemented!
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you properly balance project vs. task work? Rutilate Applying OmniFocus 5 2012-03-24 05:47 PM
Location Reminders - task-based rather than Context-based? dmcomeau OmniFocus for iPhone 17 2012-02-14 06:10 AM
Views based on context should respect the inbox scotty321 OmniFocus 1 for Mac 1 2010-02-09 09:15 AM
Does OmniFocus AppleScript support work properly yet? aleding OmniFocus Extras 3 2008-01-31 01:31 AM
Setting date based on prior task chuckbo OmniFocus 1 for Mac 0 2007-09-04 03:51 AM


All times are GMT -8. The time now is 07:03 AM.


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