I do often switch views in Omnifocus and find it quite distressing to use the mouse movements to do so. Therefore I would like to script a hotkey that toggles the view settings. As I understand there is not given hotkey to do so nor is it possible via Keyboard Maestro as there is no keyboard control in the view and the buttons are not always at the same position.
Is there a function in the scripting api I can use to do that?
Thought the same at first @CatOne, but @Nebaon is trying to switch between available and remaining without the mouse… That actually is not key-coded in OF
The only workaround I can currently think of is making two perspectives, one with available and one with remaining and switching between the two as CatOne suggested…
-- Cycle through specified state
-- v0.2
-- send feedback to sandro@sandro.org
-- use at your own peril
-- changes:
-- 0.3: removed activate command which all of a sudden no longer works
-- 0.2: removed flagged as a possible state now that it's in its own filter.
-- bring OmniFocus to the front
tell application "OmniFocus"
--activate
set theDoc to document window 1 of document 1
-- get and set needed task states
--a list of context names you want selected.
-- possible options, any combination of:"all","next", "available", "incomplete","complete"
-- this script will cycle through these states in the order that they are displayed below, so feel free to re-order them to your liking
-- BTW: incomplete = remaining if it wasn't apparent already
set availableTaskStates to {"next", "available", "incomplete", "complete"}
-- get current state
set currentTaskState to selected task state filter identifier of the content of theDoc as text
-- init next state
set nextTaskState to ""
-- get count of total number of available task states in "array"
set numberAvailableTaskStates to count (availableTaskStates)
-- identify if current state is in "array"
repeat with i from 1 to numberAvailableTaskStates
-- check to see if current state is last one in "array" and select first state, or select next available state
if currentTaskState is equal to item numberAvailableTaskStates of availableTaskStates as text then
set nextTaskState to 1
exit repeat
else if currentTaskState is equal to item i of availableTaskStates as text then
set nextTaskState to i + 1
exit repeat
end if
end repeat
-- current task state wasn't in array so just go to the first item
if nextTaskState is equal to "" then
set nextTaskState to 1
end if
-- select next task state
set selected task state filter identifier of the content of theDoc to item nextTaskState of availableTaskStates as text
end tell
and
-- Cycle Project States
-- v0.1
-- send feedback to sandro@sandro.org
-- use at your own peril
-- changes:
-- 0.2: removed activate command which all of a sudden no longer works
-- 0.1: initial release
-- bring OmniFocus to the front
tell application "OmniFocus"
--activate
set theDoc to document window 1 of document 1
-- get and set project states
-- this script will cycle through these states in the order that they are displayed below, so feel free to re-order and/or remove them to your liking
-- uncomment this next line (and comment the one after it) to enable all project states
--set availableProjectStates to {"all-projects", "active-projects", "on-hold-projects", "completed-projects"}
set availableProjectStates to {"active-projects", "on-hold-projects", "dropped-projects", "completed-projects", "all-projects"}
-- get current state
set currentProjectState to selected smart group identifier of the sidebar of theDoc as text
-- init next state
set nextProjectState to ""
-- get count of total number of available project states in "array"
set numberAvailableProjectStates to count (availableProjectStates)
-- identify if current state is in "array"
repeat with i from 1 to numberAvailableProjectStates
-- check to see if current state is last one in "array" and select first state, or select next available state
if currentProjectState is equal to item numberAvailableProjectStates of availableProjectStates as text then
set nextProjectState to 1
exit repeat
else if currentProjectState is equal to item i of availableProjectStates as text then
set nextProjectState to i + 1
exit repeat
end if
end repeat
-- current project state wasn't in array so just go to the first item
if nextProjectState is equal to "" then
set nextProjectState to 1
end if
-- select next project state
set selected smart group identifier of the sidebar of theDoc to item nextProjectState of availableProjectStates as text
end tell
Stumbled on this while searching for a way to toggle view states. Cool. It gives OF2 a backdoor to what has been missing from OF1 … a way to toggle view states.
tl;dr: Nice solution for switching outline views; looking for a solution for switching sidebar views.
I am a total AppleScript newbie, believe me. Like many, I am also:
Desperately in need of more accessible switching of views.
Astonished there’s no key shortcut for it.
For outline view switching (of tasks, in the middle panel), yes, sandro’s scripts still work. I was able to modify them into blunt instruments to select a single view so that I could put icons in the toolbar (script and screenshot below) and also configure hotkeys using Keyboard Maestro.
I would like to write similar scripts to accomplish sidebar view switching (of projects, in the side panel). After a quick look at the AppleScript dictionary for OmniFocus, I am not able to determine quite what to substitute for set selected task state filter identifier of the content of theDoc to [view].
-- Switch OmniFocus 2 "View" to "All"
-- v0.1
-- jhowell@psu.edu
-- Public domain, provided AS-IS
-- Stolen shamelessly from "Cycle Through Task States" http://www.sandro.org/omnifocus/index.php
tell application "OmniFocus"
set theDoc to document window 1 of document 1
-- select next task "All"
set selected task state filter identifier of the content of theDoc to "all"
-- possible values for "selected task state filter identifier" are:
-- "next", "available", "incomplete", "all" (also "complete")
-- in the "Show View Options" list, these values correspond to:
-- "First Available", "Available", "Remaining", "All" (nothing corresponds to "complete" in that menu)
end tell
How can I set up hotkeys in Keyboard Maestro to switch the view filter?
For example,
ctrl-1 -> First available
ctrl-2 -> Available
etc.
If “First available”, “Available”, etc. are buttons, then I could refer to them by name in KM, but for all the names I’ve tried, it doesn’t work.
Otherwise, I could program mouseclick location (after issuing shift-cmd-V), but I that doesn’t work either.
Thank you very much I just assigned all these to key commands through Keyboard Maestro. Just what I was looking for. You get the added view of only seeing complete. Thanks for posting, so helpful!