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 1 for Mac
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
Omnifocus/applescript issue when setting context Thread Tools Search this Thread Display Modes
I'm trying to change the context of an existing task using applescript.

I've got the following code:
set context of theSelectedTask to "Phone"

I have a phone context at the root level


When I try to run through the code, I get the following error:

OmniFocus got an error: Can’t make "Phone" into type context, missing value.


I've spent hours on google trying to figure it out, but all examples I find seem to be doing things the same way I am, but without the error.

I've tried changing the context and other stuff, but no luck yet.

I'm sure I'm doing something dumb, any thoughts?

greeno
 
It's often a bit easier to debug someone else's code when you can actually see it :-)

A context is not assigned by assigning the name of the context as you've done here. You have to use the actual context object associated with that name.

Here's a small example which creates a test item in the Miscellaneous project with context Home (using the parse tasks verb), then finds the context Office and assigns it to the test item instead of Home.

Code:
tell application "OmniFocus"
	tell front document
		set mytask to first item of (parse tasks with transport text "test item > Miscellaneous @Home")
		set mycontext to first flattened context where name is "Office"
		set context of mytask to mycontext
	end tell
end tell

The "flattened context" bit allows you to find a matching context even if it is nested inside another ("Errands : Office") whereas the same statement without the "flattened" adjective would only find items at the top level ("Office").
 
And if there is any chance of the code trying to assign a context which does not yet exist in the database, you may also need to add a line to create that context on the wing.

Sth like:

Code:
tell application "OmniFocus"
	tell front document
		set mytask to first item of (parse tasks with transport text "test item > Miscellaneous @Home")
		
		set lstContexts to flattened contexts where name is "Office"
		if length of lstContexts > 0 then
			set context of mytask to first item of lstContexts
		else
			set context of mytask to (make new context with properties {name:"Office"})
		end if
	end tell
end tell
 
Fantastic folks, turns out the issue with the script was with the setting of the task rather than the context. Not sure why, but all working now.
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting diagram style through Applescript ? RobTrew OmniGraffle General 2 2011-03-08 05:19 AM
Context issue brihi OmniFocus 1 for Mac 11 2010-01-08 07:13 AM
OOpro setting Styles with Applescript Simon Knight OmniOutliner 3 for Mac 1 2007-11-30 12:34 AM
Applescript - Activate Issue geoffbarrall OmniFocus Extras 2 2007-11-02 11:19 AM
Setting Task Custom Data using Applescript jubo OmniPlan General 6 2007-08-22 10:05 AM


All times are GMT -8. The time now is 03:20 PM.


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