Setting up an Inactive folder

I have a folder called “Inactive”. I want every project that is in this folder to have its status set as “On Hold” and its review period set to “4 weeks”. I’m assuming I’ll need to create a script and run it periodically, which is fine.

I’m looking for similar scripts that would allow me to cobble something together to fulfill this purpose.

1 Like

Here is a starting point.

property pFolderNametoFocus : "Inactive"

on run {}

tell application "OmniFocus"
	
	-- set focus to folder
	
	tell the document window of the default document
		set its perspective name to "Projects"
		
		--!! this part does not work !! --
		set its focus to folder whose name is pFolderNametoFocus
		
	end tell
	
	tell default document
		
		-- get the list of projects in folder
		
		set theProjectList to (id of every flattened project)
		
		-- change them
		
		repeat with theProjectID in theProjectIDList
			set (the review interval of project id ProjectID) to {steps:4, unit:week}
			set the status of project id ProjectID to on hold
		end repeat
	end tell
	
end tell
end run

The only thing that remains is to set the focus properly.


JJW

1 Like

Thank you. My Mac is in the shop, so I won’t be able to try this out for a few days. But I’ll let you know how I get on once I do.

I have some some code from elsewhere for focusing a folder:

tell application "OmniFocus" to tell the default document
	set folderList to folders whose name is "Inactive"
	tell the front document window to set focus to folderList
end tell

But AFAICT this script is missing some other pieces. It’s hard to adapt something that isn’t working :)

I think I understand the shape of what I’m trying to make from you example. Working code that might be similar to my use case would probably help me more at this point.

This should work …

property pFolderNametoFocus : "Inactive"

on run {}

tell application "OmniFocus"
	
	tell default document to set focusFolder to folders whose name is pFolderNametoFocus
	tell the front document window of default document
		
		-- focus on folder
		
		set focus to focusFolder
		
		-- get the list of projects in folder
		
		tell content to set theProjectIDList to (id of every leaf)
	end tell
	tell default document

		-- change them

		repeat with theProjectID in theProjectIDList
			set (the review interval of project id theProjectID) to {steps:4, unit:week}
			set the status of project id theProjectID to on hold
		end repeat
	end tell
end tell
end run

It only works though when the folder is in the topmost level of the Library tree. The option to find a folder in a lower level is left as an exercise for the reader. ;-)


JJW

I really appreciate your help, but this code still doesn’t work:

error "OmniFocus got an error: Can’t set project id \"j0v-G45O6Ao\" of default document to {steps:4, unit:week}." number -10006 from project id "j0v-G45O6Ao" of default document to «class 2eld»

AppleScript is maddening. It’s really hard to figure out how to do anything when there is such a lack of documentation.

Unfortunately, I cannot debug this because I don’t have your OF layout. I can suggest a few ways that you can go about the process to debug it.

  • While running this in the Applescript editor, view the “debug” window …

… to check the events. At what point does the code fail? Is it at the first project or a specific project in the list? What happens when you remove the offending project from the “Inactive” folder? Why is that project “different” from the others (that work)?

  • Add “print” statements and “comment blocks”. For example, this will allow you to see each Project ID that is to be changed without changing it …

tell default document
repeat with theProjectID in theProjectList
theProjectID
(*
set (the review …
set the status …
*)
end repeat

  • Change the code method to be “readable” in the outputs. For example, this will give you names of projects instead of ids …

tell content to set theProjectNameList to (name of every leaf)

  • Make copious use of the on-line resources about Applescript as well as the dictionary resources for OmniFocus.

Yes, Applescript can be a bear to tackle, and yes, especially for OF where “tutorials” are limited to non-existent. The end result is, when you want to use Applescript with OF and you are not an Applescript wizard steeped in the lore of OF and you want something a bit out of the ordinary, you unfortunately have to be prepared to bang your head against the wall every so often.


JJW