Applescript focus on subfolder with dialog

Dear All,

It is not obvious to me how to focus on sub-folders. I have this applescript to focus on specific stuff without having to search every time for a folder in the sidebar.

	tell application "OmniFocus"
    tell the default document	
	set folderslist to {" ", "Work", "Templates", "Personal", "Management", "Bauli", "Chiesi", "Bolton", "SDF", "University"}
	set folderList to folders whose name is (choose from list folderslist with title "Projects Focus" with prompt "Select Folder to focus on" default items " ")
	tell the front document window
		##set thePerspective to "Projects"
		##set perspective name to thePerspective
		set focus to folderList
	end tell
    end tell
    end tell

but some folders are actually sub-folders (e.g. “Client 1” is “Work : Client 1”). Now while for first-level folders it works like a charm I can’t get why the script does not like subfolders.
I tried flattened folder names, focus section, but it seems I am missing something about focus property.

Please help!

Thanks,
S

Running OF2.10 on Mac OS Sierra

If you don’t use the flattened adjective, you only get items at the top level. Your code is correct. The focus property accepts a list of project and/or folder references, focus sections.
One suggestion: since choose from list returns a list, you can store it in a variable listChoices, for example. Then perform the whose clause with the first item of this list. If not, an implicit coercion takes place.
flattened folders whose name is {"Work"} evaluates as:
flattened folders whose name is "Work".

Maybe this helps.

Code:

tell application "OmniFocus"
	tell the default document
		set folderslist to {" ", "Test", "Templates", "Personal", "Management", "Bauli", "Chiesi", "Bolton", "SDF", "University"}
		set listChoices to (choose from list folderslist with title "Projects Focus" with prompt "Select Folder to focus on" default items " ")
		set folderList to flattened folders whose name is (item 1 of listChoices)
		tell the front document window
			set focus to folderList
		end tell
	end tell
end tell
1 Like

it works!
thanks!!

only to add something useful, I use this because it is handy, but another version includes setting perspective name to “Projects”, “Contexts” or “Forecast” after the set focus command: this allows me to reduce the number of perspectives required to monitor specific groups of projects, without having a ton of perspectives on the sidebar, and reducing the number of clicks on the screen.

if anyone can complete the script by dynamically finding the folderslist from OF2 data, this would make the script fully autonomous.

So, you have one task selected, focus and a dialog appears with options "Projects", "Contexts", "Forecast"

Sure, I think this does what you want.
Code:

tell application "OmniFocus"
	tell the default document
		set folderslist to name of every flattened folder whose (hidden is false)
		set listChoices to (choose from list folderslist with title "Projects Focus" with prompt "Select Folder to focus on" default items " ")
		set folderList to flattened folders whose name is (item 1 of listChoices)
		tell the front document window
			set focus to folderList
		end tell
	end tell
end tell
1 Like

thanks again!!

You’re welcome!

I feel as though I’ve seen you answering and solving so many AppleScript questions lately. I don’t use AppleScript or even the Mac version of OmniFocus these days, but I still wanted to say thank you.

You’re very kind. You answered a lot of questions here, so thank you.