Pause OneDrive Syncing When Connected to Specific WIFI Network

Hi There,

I'm new to KM and have been Googling the heck out of this question, but without any luck. I would like to pause OneDrive sync when connected to a specific wifi network (my mobile hotspot).

I know I can use the wireless network as a trigger (this works well), but can't figure out how to pause OneDrive Sync.

Usually, to pause OneDrive sync you have to click on the status menu icon, click [More...] and then click "Pause Syncing" then click "2 hours"
The Pause isn't available as a menu item (that I've been able to find). It's only accessible through the status menu. I can't seem to use "image search" because the status icon changes and is animated.

In terms of AppleScript. I've gotten as far as being able to click the OneDrive status icon, but can't get any further (see code below).

tell application "System Events"
   tell UI element "OneDrive"
      tell menu bar item 1 of menu bar 2
         perform action "AXPress"
      end tell
   end tell
end tell

Would love any help!!!

Hey Yevgeny,

Welcome to the Keyboard Maestro Forum!  :smile:

Working with UI-Scripting is not easy and there is little documentation.

Nevertheless this task was amenable to a little persistent investigation (of course I've been UI-Scripting a bit longer than you have).

------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2019/09/01 18:27
# dMod: 2019/09/01 18:27 
# Appl: OneDrive, System Events
# Task: Pause OneDrive Syncing
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @OneDrive, @System_Events
------------------------------------------------------------

tell application "System Events"
   tell application process "OneDrive"
      
      tell menu bar 2
         tell menu bar item 1
            perform action "AXPress"
         end tell
      end tell
      
      tell window "Microsoft OneDrive"
         tell button "More"
            perform action "AXPress"
         end tell
         
         tell (first UI element whose name is "Pause Syncing")
            perform action "AXPress"
         end tell
         
         tell (first UI element whose name is "24 Hours")
            perform action "AXPress"
         end tell
         
      end tell
      
      tell menu bar 2
         tell menu bar item 1
            perform action "AXPress"
         end tell
      end tell
      
   end tell
end tell

------------------------------------------------------------

-Chris

1 Like

You are a god among men, Chris.

1 Like