I’d like to use ControlPlane to set some contexts to ‘Active’ or ‘On Hold’ programmatically. I have plenty of programming experience, but hardly any Applescript scripting experience. Hard to tell from the Dictionary if anything like this would be possible at all.
So the first question is: can it be done? Can you toggle the status of a Context programmatically?
And if not: is that a feature that can be added, pretty please?
Here is an AppleScript that I use to toggle between work and play contexts. Feel free to modify it as your needs demand.
(*
This script toggles between work and play contexts
*)
property pWorkContexts : {"Work", "Colleagues"}
property pPlayContexts : {"house", "farm", "errands", "Personal", "bills"}
on run
-- set location
set theLocation to ¬
(choose from list {"Work", "Play", "Both"} with title "Where are you?")
if theLocation is equal to {"Work"} then
set patWork to true
set patPlay to false
end if
if theLocation is equal to {"Play"} then
set patWork to false
set patPlay to true
end if
if theLocation is equal to {"Both"} then
set patWork to true
set patPlay to true
end if
-- toggle OF contexts and synchronize
tell application "OmniFocus"
tell front document
repeat with pContext in pWorkContexts
set idtoToggleList to every item of (complete pContext as context)
repeat with pLC in idtoToggleList
set idtoToggle to id of pLC
--set idContext to first item of (every flattened context where id contains idtoToggle)
tell context id idtoToggle to set its allows next action to patWork
end repeat
end repeat
repeat with pContext in pPlayContexts
set idtoToggleList to every item of (complete pContext as context)
repeat with pLC in idtoToggleList
set idtoToggle to id of pLC
--set idContext to first item of (every flattened context where id contains idtoToggle)
tell context id idtoToggle to set its allows next action to patPlay
end repeat
end repeat
end tell
synchronize
end tell
end run
–
JJW
3 Likes