I've look through the forums (and several OF scripting sites) and perhaps I'm not searching well but I just want to know how to create a new item, something like "'tell OmniFocus make new item with title 'title' context 'context' project 'project'".
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!
|
|
FAQ | Members List | Calendar | Today's Posts | Search |
Basic new item script | Thread Tools | Search this Thread | Display Modes |
Member
2012-05-20, 08:48 PM
I've look through the forums (and several OF scripting sites) and perhaps I'm not searching well but I just want to know how to create a new item, something like "'tell OmniFocus make new item with title 'title' context 'context' project 'project'".
Post 1
|
The easiest way to do this is to use the "parse tasks" command. This lets you piggy-back on top of the code that parses emails and turns them into OmniFocus actions.
See this thread for an example of this approach in action. Hope this helps!
Post 2
|
Member
2012-05-21, 12:57 PM
Thanks for your response. I'm going to have to read that post a few times; I've never heard of Alfred and it all seems very complex compared to what I want to do. So you're saying there's no direct way to create an OmniFocus item from AppleScript?
Post 3
|
Member
2012-05-21, 12:59 PM
No, Brian was saying that there's a AppleScript facility called parse tasks, which was used by the author of the script in the thread he pointed out to you to do something similar. In the mean time, I wrote a post telling you how to do it the harder way :-)
Making an action in the Inbox is pretty straightforward; it's a little more complex when you want to put the action in a project, because you have to specify where it goes. This will make a task in the Inbox: Code:
tell application "OmniFocus" tell default document make new inbox task with properties {name:"Sample task", note:"This is a short note"} end tell end tell Code:
property pContext : "Mail" tell application "OmniFocus" tell default document set MyContext to my GetMyContext(pContext) make new inbox task with properties {name:"Sample task", note:"This is a short note", context:MyContext} end tell end tell -- Search all contexts for strContext, return first one found with strContext in name. Handles nested contexts. on GetMyContext(strContext) tell application "OmniFocus" tell default document set lstContexts to flattened contexts where name contains strContext if (length of lstContexts > 0) then return (first item of lstContexts) else return (missing value) end if end tell end tell end GetMyContext Code:
property pContext : "Mail" property pProject : "Miscellaneous" tell application "OmniFocus" tell default document set MyContext to my GetMyContext(pContext) set MyProject to my GetMyProject(pProject) if (MyProject is not missing value) then tell MyProject set myTask to make new task at end with properties {name:"Sample task", note:"This is a short note", context:MyContext} end tell else make new inbox task with properties {name:"Sample task", note:"This is a short note", context:MyContext} end if end tell end tell -- Search all contexts for strContext, return first one found with strContext in name. Handles nested contexts. on GetMyContext(strContext) tell application "OmniFocus" tell default document set lstContexts to flattened contexts where name contains strContext if (length of lstContexts > 0) then return (first item of lstContexts) else return (missing value) end if end tell end tell end GetMyContext -- Search all project names for strProject, return first one found with strProject in name. on GetMyProject(strProject) tell application "OmniFocus" tell default document set lstProjects to flattened projects where name contains strProject if (length of lstProjects > 0) then return (first item of lstProjects) else return (missing value) end if end tell end tell end GetMyProject
Post 4
|
Member
2012-05-21, 01:10 PM
If you wanted to do the same thing as the last version with the parse tasks verb, it might look like this:
Code:
tell application "OmniFocus" tell default document set strParseTasks to "Sample task @ Mail > Miscellaneous " & return & "This is a short note" set theResult to parse tasks with transport text strParseTasks with as single task end tell end tell
Post 5
|
Member
2012-05-21, 01:12 PM
The format understood by parse tasks is documented in the online help for OmniFocus, under the title "Processing Mail messages into actions". With a little fiddling about, you can set up OmniFocus to parse selected email messages and turn them into actions so that others can be making your list of things to do longer even as you are attempting to make it shorter :-)
Post 6
|
Member
2012-05-21, 02:50 PM
Thanks very much. Is this documented anywhere (besides the dictionary)?
Post 7
|
Member
2012-05-21, 02:58 PM
Various scripts that people have sussed out, forum posts...one very helpful thing is to get Late Night Software's Script Debugger and use the Explorer functionality to browse all the data structures exposed by AppleScript. Some of this stuff is challenging to decipher if you have to figure it out by reading the dictionary, but much clearer when you can see what it looks like.
Post 8
|
Member
2012-06-20, 02:18 PM
I had a problem with the scripts in that the GetMyContext and GetMyProject functions were passed to OmniFocus instead of the functions in the script, Omnifocus returned an error. I moved the calls out of the tell statements and it worked like a charm. Thanks.
Post 9
|
Guest
2012-06-20, 11:32 PM
A transcription glitch ? whpalmer4's scripts run as is if copied and pasted …
I wonder if the my keyword got dropped ? ( You can call a script-defined function within the tell … end tell scope as long as you precede it with my, to specify that it is a script level function, rather than a method of the current object )
Post 10
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
setting project + context via script (modifying a DEVONthink script) | bernd | OmniFocus Extras | 2 | 2012-09-08 12:10 PM |
Script: Clear start/due dates of selected item(s) | dbyler | OmniFocus Extras | 0 | 2010-06-15 10:17 AM |
Very basic time tracking script | ganwell | OmniFocus Extras | 2 | 2009-11-27 10:08 AM |
very basic help | scottnh | OmniFocus Syncing | 6 | 2008-10-16 11:33 PM |