Wanted: Macro to Pause Dropbox and Google Drive

I want to create a macro that toggles Dropbox and Google Drive synching on an off. I’m currently doing this manually before I do any live streaming. I need all the available bandwith I can get, and I don't want these two apps using bandwidth to sync. Does anyone know how to do this? Thanks.

I found part of the answer. I can use this Apple Script to pause and/or resume synching in Dropbox

tell application "System Events"

   -- Pause syncing
   click menu bar item 1 of menu bar 2 of application process "Dropbox"
   click menu item "Pause Syncing" of menu 1 of menu bar item 1 of menu bar 2 of application process "Dropbox"
   
   delay 2

   -- Now re-enable syncing
   click menu bar item 1 of menu bar 2 of application process "Dropbox"
   click menu item "Resume Syncing" of menu 1 of menu bar item 1 of menu bar 2 of application process "Dropbox"

end tell

Hey Michael,

Good for you for working with System Events to handle Dropbox. Most people don't want to work that hard...  :sunglasses:

I spent a long time trying to UI-Script Google Drive, and I found:

  • Google has made one nasty app.
     
  • Accessibility in it is broken.
    • I got things working, and then they'd fail on another activation.
      • This was grossly repeatable, so I finally gave up.

I finally used a combination of UI-Scripting and Keyboard Maestro's click at found image action to produce a macro that works reliably on my Mojave system. It's acceptably quick too.

You'll have to fiddle a bit to get an image that will work reliably, and you can Quick Look mine in the image well to see what I did.

Good luck.

-Chris


Google Drive ⇢ Toggle Syncing.kmmacros (27 KB)

Macro-Image

Keyboard Maestro Export

Hey Michael,

Does the script hang for about 6 seconds on Monterey?

I have a method to get around that if so.

-Chris

1 Like

Yes, it does. I'd love to hear about your workaround. Thanks.

That worked astonishingly well on Monterey. I simply replaced your image action with this one. Thanks!

1 Like

Chris, I hope you don't mind, but I combined my macro with yours. This new macro toggles synching on Google Drive and Dropbox. I use a Stream Deck key to trigger it. Thanks for your help!

Toggle Synching of Google Drive and Dropbox.kmmacros (29 KB)

Hey Michael,

Okay, here's how that works:

  • AppleScript UI-Scripting is used to find the position of the Dropbox icon in the menu bar.

  • Keyboard Maestro clicks it to open the menu and that prevents the hang.

  • Back to UI-Scripting to select the menu items.

It works very reliably on my Mojave system.

-Chris


Toggle Dropbox Syncing v1.00.kmmacros (7.6 KB)

Macro-Image

Keyboard Maestro Export

That is VERY cool! Works like a charm. Thanks so much.

1 Like

@ccstone, do you know how to create a similar macro for Backblaze? I tried to modify your Dropbox example above, but Backblaze doesn't use a similar name for toggling pause and sync. For example, in your macro you have this:

tell item 1 of (get menu items whose enabled is true and name contains "Syncing")

However, in Backblaze, when you option-click on the Backblaze menu bar icon, you get either "Backup Now" or "Pause Backup." Unfortunately, there’s more than one menu item that includes the word "Backup."

There are two commands that you can use to pause and then resume Backblaze:

/Library/Backblaze.bzpkg/bztransmit -pausebackup --Pauses Backblaze
/Library/Backblaze.bzpkg/bztransmit -completesync --Resumes Backblaze

However, this would require knowing the state of Backblaze. I haven't been able to figure that out.

Thoughts?

Hey Michael,

I don't have Backblaze to test with, so here's a guess:

tell application "System Events"
   tell application process "Backblaze"
      tell menu bar 2
         
         tell menu bar item 1
            
            if exists of menu item "Backup Now" then
               
               tell menu item "Backup Now" to perform action "AXPress"
               
            else if exists of menu item "Pause Backup" then
               
               tell menu item "Pause Backup" to perform action "AXPress"
               
            end if
            
         end tell
         
      end tell
   end tell
end tell

As for the shell commands…

Get help in the Terminal:

bztransmit -h

Try:

-testify

And see if it gives you any output.

I didn't see any other command that looked promising, but you should look them over carefully.

If there's not a command that returns the activate state of the app then they're crazy...

-Chris

Thanks, Chris. That is very close to what I did. Thankfully, the menu item is in the same position everytime, so it can be toggled. Here's what I came up with:

Thanks for your help!

1 Like

For some reason, this macro has stopped working. It invokes the initial Dropbox menu, but it won't select the pause syncing or resume syncing option. Do you know of a workaround? Thanks.

Hey Michael,

Because Dropbox has broken accessibility in version 139.3.4817!

Please take the time to complain to Dropbox...

There is no workaround for AppleScript UI-Scripting, so the only thing to do is resort to a found image.

Carefully note the settings in the gear menu of the Found Image actions – they affect how the try-catch action works.

-Chris

Toggle Dropbox ⇢ Found Image ⇢ v1.00.kmmacros (83 KB)

Macro-Image

Hi,

Sorry to wake up this old thread but it seams like Dropbox is again letting the AppleScripting work.

I'm not into scripting and I would like to know if there is a way to make this a non toggle script? I want to pause dropbox when I use some specific audio apps that don't like files being synced while working on them.

Right now the script works but I'm afraid that the toggle will get "out of sync" so to say :slight_smile: so it will be syncing when the app is open and vice versa...

Could this be done?

Try replacing the second AppleScript in the macro from post #8 with this:

--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2021/11/27 01:05
# dMod: 2022/11/08 20:56
# Appl: Dropbox, System Events
# Task: Pause Dropbox Sync – Use with Keyboard Maestro.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Dropbox, @System_Events, @Toggle, @Dropbox, @Sync
--------------------------------------------------------

tell application "System Events"
   tell application process "Dropbox"
      tell menu bar 2
         tell menu bar item 1
            tell menu 1
               if exists of menu item "Pause Syncing" then
                  tell menu item "Pause Syncing"
                     perform action "AXPress"
                  end tell
               end if
            end tell
         end tell
      end tell
   end tell
end tell

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

Thanks!

So nice of you to look into this.

I have it set up so it triggers both when the app activates and closes, and would like to have this happening with two different apps.

How to do that I'm not sure. Can one action do that?

So I won't get issues when closing one app while the other is open.

Sorry if I'm not making sense, but coding is not one of my strong sides :wink:

You mean one macro? You could do that, but it would get complicated.

I think it would be simplest to create three global macros.

One – to pause Dropbox whenever app-1 or app-2 launches.

Dropbox Deactivator for Google Chrome & Safari.kmmacros (4.7 KB)
Keyboard Maestro Export

Two – a macro to monitor if app-1 quits.

  • If app-2 is NOT running then it would un-pause Dropbox and unset the DropboxOffFlag variable.
  • If app-2 IS running then do nothing.

Three – a macro to monitor if app-2 quits.

  • If app-1 is NOT running then it would un-pause Dropbox and unset the DropboxOffFlag variable.
  • If app-1 IS running then do nothing.

KISS is important when building this sort of macro.

(Keep It Sufficiently Simple)

This helps you in the building, debugging, and maintenance phases – and you're likely to learn something while building the system.

Depending upon what you learn you may choose to streamline things in the future – or not...

1 Like

Hi,

Sorry for my late reply!

Got sick with Covid and was behind with work when I got back, so I forgot about my sync issues for a while :wink:

Thanks a lot for your suggestion!! I really appreciate it. I will try this as soon as I get some time.

Have a Happy New Year!

1 Like