I want to perform an action on some data stored in Dropbox. If Dropbox is currently sync-ing, I wan to wait until it’s finished. If it’s not sync-ing, I want to perform it as soon as possible.
I could use the “found image” condition, and build the capability around the difference in the various dropbox icons, but generally would only use that as a last resort.
How can I tell that Dropbox is in the middle of syncing files?
There’s not a neat, organic way to do this as far as I know.
It should be possible to simply ask Dropbox what it’s doing, but they haven’t provided a scripted interface for the Mac.
The is a workaround however using AppleScript and System Events.
You can run this from the Script Editor to see what it does.
------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2015/07/19 01:47
# dMod: 2015/09/06 13:00
# Appl: Dropbox and System Events
# Task: Get Dropbox Status
# Tags: @Applescript, @Script, @System_Events, @Dropbox, @Status
------------------------------------------------------------
tell application "System Events"
tell UI element "Dropbox"
tell menu bar 2
tell menu bar item 1
set dropBoxStatus to help
# Uncomment to click the Dropbox menu icon.
# perform action "AXPress"
end tell
end tell
end tell
end tell
set kmVariableName to "myVariableName"
tell application "Keyboard Maestro Engine"
try
set value of variable kmVariableName to dropBoxStatus
on error
make new variable with properties {name:kmVariableName, value:dropBoxStatus}
end try
end tell
------------------------------------------------------------
You’ll get output that looks like this:
"Dropbox 3.9.41
Uploading \"Aquamacs-Emacs-3.2.dmg\" (481.8 KB/sec, 1 min left)"
Or this when Dropbox is synced up.
"Dropbox 3.9.41
Up to date"
So your macro can test for whatever-variable-name contains “Up to date” and continue when it does.
Apple broke this approach in Sierra, and I don’t know if it’s fixed in High Sierra.
On my Sierra system this takes over 6 seconds to run.
------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2015/07/19 01:47
# dMod: 2017/12/02 05:44
# Appl: Box Sync and System Events
# Task: Get Box Sync Status
# Tags: @Applescript, @Script, @System_Events, @Box_Sync, @Status
------------------------------------------------------------
tell application "System Events"
tell UI element "Box Sync"
tell menu bar 2
tell menu bar item 1
perform action "AXPress"
tell menu 1
tell menu item 1
set syncStatus to its enabled
end tell
perform action "AXCancel"
end tell
end tell
end tell
end tell
end tell
------------------------------------------------------------
@JMichaelTX gave me an idea of how to speed that up.
Try this one.
-Chris
----------------------------------------------------------------
# Auth: Christopher Stone (with input from @JMichaelTX)
# dCre: 2015/07/19 01:47
# dMod: 2017/12/09 22:49
# Appl: Box Sync and System Events
# Task: Get Box Sync Status
# Tags: @Applescript, @Script, @System_Events, @Box_Sync, @Status
----------------------------------------------------------------
try
ignoring application responses
tell application "System Events"
tell UI element "Box Sync"
tell menu bar 2
tell menu bar item 1
perform action "AXPress"
end tell
end tell
end tell
end tell
end ignoring
set shCMD to "killall 'System Events'"
do shell script shCMD
tell application "System Events"
tell UI element "Box Sync"
tell menu bar 2
tell menu bar item 1
tell menu 1
tell menu item 1
set syncStatus to its name
end tell
perform action "AXCancel"
end tell
end tell
end tell
end tell
end tell
syncStatus
on error e number n
set e to e & return & return & "Num: " & n
if n ≠ -128 then
try
tell application (path to frontmost application as text) to set ddButton to button returned of ¬
(display dialog e with title "ERROR!" buttons {"Copy Error Message", "Cancel", "OK"} ¬
default button "OK" giving up after 30)
if ddButton = "Copy Error Message" then set the clipboard to e
end try
end if
end try
----------------------------------------------------------------
I took Chris' script and turned it into a KM Action Group "Pause Until DropBox Sync Completes". I have confirmed this runs fine with Keyboard Maestro 8.2.4 on macOS 10.14.5 (Mojave).
Here's an upload of these ACTIONS which you can insert where ever you need them:
I believe that @JMichaelITX's solution doesn't work anymore with newer version of Dropbox. It worked for me for a good few years, but, when I run their script now, it returns the following error:
2022-03-11 17:57:13 Execute an AppleScript failed with script error: text-script:1124:1134: execution error: Can’t get every paragraph of missing value. (-1728)
I have tried a bit to fix it. Unfortunately, I am not that experienced with Applescript.
Does anyone have a solution to fix this script?
(I understand that JMichaelITX has passed away. RIP.)
Revised as promised:
There is an acknowledged bug in Dropbox. Dropbox is not returning the correct status on all platforms. I noticed it on the Apple M1. They acknowledged that it’s their bug. But since I’m the only one that reported it, it stuck at a low priority. Please report it to Dropbox.
I have a workaround, in KM, but it’s a hack. Dropbox must fix it.
Thanks, @ikenassi! Can you share the message you sent to Dropbox, so I can tweak/rewrite it and share a similar message with them? Also, how did you report it to the? I don't see a way to do so.
Here you go. I had to upload in two pages, each had to be a jpg. I sent the original report to their support site, and when they asked for more info, I sent them this info, which I generated from Xcode's Accessibility Inspector Developer Tool: