Switch context status script

I’m looking for a script or other quick mean to switch to “active/on hold” a series of different contexts depending if I’m home or at work. Somebody could help?

Yes, I can help. Can you give more details?

I use this code …

(*
    This script toggles contexts between work, personal, and others
*)

property pVersion : "2.3"
property pWorkContexts : {"Office", "Work", "Lab"}
property pPersonalContexts : {"Homes", "errands", "Personal", "bills"}
property pFocusOffContexts : {"start", "someday", "WoO"}

property gCurrentLocation : "All"

property pTitle : pVersion & ": Where are you?"

on run
    
    -- set everything to default
    
    set patWork to false
    set patPersonal to false
    set patFocus to false
    
    -- set location
    
    set theLocation to ¬
        (choose from list {"Focus", "Work", "Personal", "All"} with title pTitle default items gCurrentLocation)
    
    if theLocation is false then return
    
    if theLocation is equal to {"Focus"} then set patFocus to true
    if theLocation is equal to {"Work"} then set patWork to true
    if theLocation is equal to {"Personal"} then set patPersonal to true
    if theLocation is equal to {"All"} then
        set patWork to true
        set patPersonal to true
    end if
    
    set gCurrentLocation to theLocation
    
    -- 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
                    tell context id idtoToggle to set its allows next action to patWork
                end repeat
            end repeat
            repeat with pContext in pPersonalContexts
                set idtoToggleList to every item of (complete pContext as context)
                repeat with pLC in idtoToggleList
                    set idtoToggle to id of pLC
                    tell context id idtoToggle to set its allows next action to patPersonal
                end repeat
            end repeat
            repeat with pContext in pFocusOffContexts
                set idtoToggleList to every item of (complete pContext as context)
                repeat with pLC in idtoToggleList
                    set idtoToggle to id of pLC
                    tell context id idtoToggle to set its allows next action to not patFocus
                end repeat
            end repeat
        end tell
        synchronize
    end tell
    
    -- send notice to center
    
    set theNotice to "You are now at " & the text of theLocation
    display notification theNotice with title "Applescript: Toggle OF Location" subtitle ((current date) as text)
    delay 1
end run

(post edit: fixed mistake where patUAH should have been patWork)


JJW

1 Like

It worked perfectly with few little tweaks to match my contexts!! Thank you so much!