AppleScript to create a Project inside a folder?
Hello All,
Using an applescript, I would like to create a project inside a designated folder. but I am having difficulty with the correct way to tell Omnifocus where to create the project (it keeps placing it at the document (root) level). I have the folderName and the folderID and am happy to use whichever (though I'd prefer the folderID). the line for creating the project that I am using is ========= make new project with properties {name:ProjectName, note:ProjectNote, XXX} ========= I've tried: container:FolderID container:FolderName folder:FolderID folder:FolderName and tried different keywords after the properties close-bracket, but to no avail. Any help would be greatly appreciated. Thanks in advance! Ricky |
[code]set myFolder to folder id folderID
set myProject to make new project with properties {name:ProjectName, note:ProjectNote} at end of projects of myFolder [/code] |
Perfecto!!
Thank you so much. That was exactly what I was looking for |
Is this the complete code necessary? Can I run the script with just this and it will work? Thankee.
|
[QUOTE=Christian;108884]Is this the complete code necessary? Can I run the script with just this and it will work? Thankee.[/QUOTE]
Hi Christian, This is what I am using. (Note that it is part of a bigger script, and so some variables are not properly declared in the example below) -Ricky [CODE] (* Since this code is copied from part of a larger script, it is missing the variable declerations. Make sure to Set Variables as needed: set FolderName to ... set ProjectName to ... etc… *) tell application "OmniFocus" --activate set theDoc to default document tell theDoc set StatusContext to context "ContextInHere" of context "ParentContext" --modify as needed --Create the folder with Project and Task set NewAcctFolder to (make new folder with properties {name:FolderName} at end of folder id RootFolderID) set NewOppProject to (make new project with properties {name:ProjectName, note:ProjectNote, context:StatusContext} at end of projects of NewAcctFolder) set NewStatusTask to (make new task with properties {name:TaskName, note:TaskNote, context:StatusContext} at end of tasks of NewOppProject) end tell end tell [/CODE] |
Grand, thanks for the quick reply! I'll test this tomorrow, could save some time for work projects.
|
FWIW it's also possible to nest the [I]make[/I] commands within the scope of the appropriate parent objects using [I]tell ... end tell[/I].
The new objects will be placed, by default, at the end of that parent's children. [CODE]tell application id "OFOC" tell default document set oContext to first flattened context where name = "Library" tell (first flattened folder where name = "Reading Cycles") tell (make new folder with properties {name:"Shakespeare"}) tell (make new project with properties {name:"Lear", note:"Sturm und drang", context:oContext}) to ¬ make new task with properties {name:"First reading", note:"Skip the critical theory at this stage", context:oContext} end tell end tell end tell end tell[/CODE] |
[QUOTE=RobTrew;108916]The new objects will be placed, by default, at the end of that parent's children.
[/quote] And if you should need them placed elsewhere, you can insert the necessary specification: [code] tell application id "OFOC" tell default document set oContext to first flattened context where name = "Library" tell (first flattened folder where name = "Reading Cycles") tell (make new folder with properties {name:"Shakespeare"}) tell (make new project with properties {name:"Lear", note:"Sturm und drang", context:oContext}) to ¬ make new task with properties {name:"First reading", note:"Skip the critical theory at this stage", context:oContext} tell (make new project with properties {name:"Othello", note:"Jealousy drives men mad", context:oContext}) to ¬ make new task with properties {name:"First reading", note:"Joe Green thinks this might make a good opera, agree?", context:oContext} tell (make new project with properties {name:"Julius Caesar", note:"Beware the Ides of March!", context:oContext} [b]at after first project[/b]) to ¬ make new task with properties {name:"First reading", note:"Skip the critical theory at this stage", context:oContext} end tell end tell end tell end tell [/code] |
Some good reading projects developing here :-)
|
flattened?
Hi Rob / Whpalmer,
Thanks for the extra tips, much appreciated. Out of curiosity, how does the term flattened work? what happens if it is omitted? Thanks Ricky |
If you don't use the flattened adjective, you only get the items at the top level. With Rob's example script, if you ran it against an OmniFocus database where you had a nested context called Errands:Library instead of Library, it would not find the Errands:Library context and thus none of the created actions would have a context assigned.
Prior to the advent of the flattened adjective, one had to write some additional code to walk through the entire structure, looking for such matches. Many scripts didn't bother... |
All times are GMT -8. The time now is 12:53 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.