Omnifocus/applescript issue when setting context
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 [/code] 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[/CODE] |
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.
|
All times are GMT -8. The time now is 04:33 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.