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

 
AppleScript to create a Project inside a folder? Thread Tools Search this Thread Display Modes
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
 
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:
Originally Posted by Christian View Post
Is this the complete code necessary? Can I run the script with just this and it will work? Thankee.
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
 
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 make commands within the scope of the appropriate parent objects using tell ... end tell.

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
 
Quote:
Originally Posted by RobTrew View Post
The new objects will be placed, by default, at the end of that parent's children.
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} at after first project) 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
 
Some good reading projects developing here :-)
 
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
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recovering project folder and tasks inside liz4cps OmniFocus 1 for Mac 3 2012-10-06 01:38 AM
How to create a project inside another project Don Richmond OmniFocus for iPad 7 2012-08-27 06:23 PM
How to I create a new folder and or project with mail rules? tlester OmniFocus 1 for Mac 2 2012-03-15 01:06 PM
Open or Create Project Folder Script ptone OmniFocus Extras 0 2008-08-11 12:17 PM
Create project in folder by Cmd-Enter Schimmi OmniFocus 1 for Mac 1 2008-01-08 05:02 PM


All times are GMT -8. The time now is 04:09 AM.


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