Simple Script for adding new project

Like many here, I add a lot of projects to my OF2 system, and it’s easy for them to get lost in the shuffle. I’m trying to improve this with a new approach and an AppleScript. So far, it’s working pretty well.

I hope you find the ideas and the script helpful.

I set up a capture system for new projects, just like the InBox for new tasks. I created a subfolder of my “GTD” folder called “NEW PROJECTS.” I also have a context in my system for reminders.

I launch the script from a Keyboard Maestro trigger that’s available in all apps. Kind of like the OF2 Quick Entry window. When you trigger the macro, the script asks you to name the new project. It then automatically creates the project in the capture folder, and adds a new task assigned to the reminder folder that has a message containing the name of the new project.

The message can be anything useful. I use a reminder to process the project I just created.

The result is that you capture the name of the new project and move on with your day. Later, when looking over your reminders, there’s a task telling you to deal with the new project you added.

I’m not knowledgable enough at AppleScript to include a backlink to the new project in the notes section of the reminder task. I don’t understand POSIX paths and the like. If someone would like to improve this script by adding a project backlink, I’d appreciate it.

Here is the script. You have to substitute your own data for the text marked [like this]

tell application "OmniFocus"
	
	display dialog "What's the New Project?" default answer "New_Project" buttons {"Cancel", "OK"} default button 2
	
	
	set newProjectName to (the text returned of the result)
	
	
	tell default document
		set theFolder to folder named [your folder name in quotes] of folder [its parent folder name in quotes]		
		set MyContext to context [the context you want to use in quotes]
		
		
		tell theFolder
			make new project with properties {name:newProjectName}
			
			set theProject to first flattened project where its name is newProjectName
			set theTask to [your reminder text in quotes trailed by a space] & newProjectName
			
			
			tell theProject to make new task with properties {name:theTask, context:MyContext, flagged:true}
			
			
			
		end tell
	end tell
end tell

Hey @anamorph! Here’s a modified version. It does not do everything exactly the same (e.g. it dumps to a top-level folder rather than a sub-folder). However, it puts options at the top, tightens up the syntax (e.g. checks for the context and sets theContext as a context), and adds some security (e.g. try/on error in case the folder does not exist).

(*
version 0.2 -- modified jjw
*)
property pDialog : "What is the new Project's name?" -- the dialog prompt
property pDefaultProject : "Reminders" -- the default project name
property pFolder : "Reminders Folder" -- the folder name
property pContext : "do" -- the name of the context for the reminder task
property pTask : "get started with this project" -- the task statement

property bypassdialog : false -- set to true to always dump a new task in to the default project

on run

if (not bypassdialog) then
	display dialog pDialog ¬
		default answer pDefaultProject buttons {"Cancel", "OK"} ¬
		default button "OK" with title "Choose a Project Name"
	if (result = {button returned:"Cancel"}) then
		return
	else
		set newProjectName to (the text returned of the result)
	end if
end if


tell application "OmniFocus" to tell default document
	try
		set theFolder to folder named pFolder
	on error
		make new folder with properties {name:pFolder}
		set theFolder to folder named pFolder
	end try
	try
		set theContextID to id of first item of (complete pContext as context)
	on error
		display dialog "Your Drop Context is not defined properly. Script must abort." buttons {"OK"} default button "OK" with title "Failure Notice"
		return
	end try
	set theContext to (first flattened context whose id is theContextID)
	tell theFolder
		make new project with properties {name:newProjectName}
		set theProject to first flattened project where its name is newProjectName
		tell theProject to make new task with properties {name:pTask, context:theContext, flagged:true}
	end tell
end tell

end run

I hope this might provide a guide for you to expand what you have. For example, the next step migth be to check for the pre-existence of the Project in the Folder and append to it rather than creating a new one each time.

ps – I’d have to munge around with paths and POSIX paths as well until I could get exactly what you want.


JJW

Thanks for the tidier version – it’s useful and instructional.

If you get the chance, I’d appreciate the help.

I’m curious. My script creates this hierarchy …

  • Folder (Reminder Notes) <- Project (Reminders) <- Task (reminder note)

I think you wanted this instead …

  • Folder (New Projects) <- Project (New Project)
  • Folder (Reminder Notes) <- Project (Reminders) <- Task (reminder note with link to above)

If so, I think what you want is an internal URL link in the note field, not a POSIX path.


JJW

When my script makes the new Project, it creates a subtask that I use as a reminder to process and file the new project. That way, when I look at my TODAY Perspective, there’s a context with a list of reminders about the projects I’ve added.

I’d like that reminder task to have a clickable link that will open the parent project. Just to make the process faster.

I don’t know enough about POSIX or internal URLs to know which is more appropriate or how to do either of them correctly.

While we’re talking about it, I have a related script that notifies me when I scan something into my DropBox. I’d like to be able to include a link in the task notes that will take you to the file in Dropbox.

Any suggestions appreciated.

Here is the way to create a URL in OmniFocus to link back to a Project. Use this example to generate the link and then add it as a note property to the task. If I understand what you want, substitute pProjectName by newProjectName in the previous script.

property pURL : "omnifocus:///task/" -- do not change this
property pProjectName : "Weekly Review" -- the name of the Project
on run
tell application "OmniFocus" to tell default document
	set theProjectID to the id of the first flattened project where its name is pProjectName
	set theLink to pURL & theProjectID
            -- add theLink to the note field of the Project
end tell
end run

As for generating URLs to point back to external files … I’d be likely to take a while longer to get an answer for you.


JJW

Thanks very much for your patience and generosity. I’ll try this today.

Thanks for looking into URLs to point back to external files as well.

You are truly an ace, as your avatar shows. ;-)