Set focus of Forecast view with AppleScript

I enjoy using the Forecast view with it’s lovely sidebar calendar, but often want to quickly narrow it down to “work” items vs. “personal” items. I was wondering if it would be possible to do this with AppleScript. Here’s what I cooked up, which doesn’t work.

tell application "OmniFocus"
	tell front document
		set focus of document window 1 to "Work"
	end tell
end tell

(I’m an AppleScript newbie.) Any tips?

Thanks world,

Dave

I’m guessing “Work” is a folder? If so, you want something like this:

tell application "OmniFocus"
	tell the default document
		set folderList to folders whose name is "Work"
		tell the front document window
			set focus to folderList
			set selected sidebar tab to forecast tab
		end tell
	end tell
end tell

Hope that helps!

1 Like

This works great! Thank you! The only thing of note is that the first " before Work was a smart quote. I ironed it out and now the script works perfectly.

I love this because I get the calendar in the sidebar and I can focus on today’s (or any day’s) due items for work, personal or both.

Thanks again,

Dave

This is a helpful script. Any way to specify more than one folder? I get an AppleScript error that I am using an illogical comparison if I script “whose name is X or Y” or “whose name is X and Y”.

This will work …

property pFocusList : {"Work", "Office", "Stockroom"}

tell application "OmniFocus"
	tell the default document
		set folderList to (folders whose name is first item of pFocusList)
		repeat with folderName in rest of pFocusList
			set theFolder to (folders whose name is folderName)
			set folderList to theFolder & folderList
		end repeat		
		tell the front document window
			set focus to folderList
			set selected sidebar tab to forecast tab
		end tell
	end tell
end tell


JJW

Fantastic, thanks!

Any chance you can adapt this to include projects as well?

Set q to "My folder or project"

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

Try this (untested) …

property pProjectList : {"My First Project", "My Second Project", ...}

...

set projectList to (project whose name is first item of pProjectList)

IOW, change all occurrences of folder to project


JJW

Thanks DrJJWMac,

I ended up using this:

Set q to "Project name"

    tell application "OmniFocus"
    	tell the default document
    		set FocusProject to (every flattened project whose name is q)
    		tell the front document window
    			set focus to FocusProject
    		end tell
    	end tell
    end tell

You could tighten this a bit …

property pProjectName : "Project Name"
on run
	tell application "OmniFocus" to tell the default document
		set FocusProject to (every flattened project whose name is pProjectName)
		tell the front document window to set its focus to FocusProject
	end tell
end run


JJW

Hi DrJJWMac,

Implemented! 😃

Thanks for that.

jhn