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 "DropBoxIke"
--tell application "Keyboard Maestro Engine"
-- try
-- set value of kmVariableName to dropBoxStatus
-- on error
-- make new variable with properties {name:kmVariableName, value:dropBoxStatus}
-- end try
--end tell
It returns my Dropbox status fine... did you recently do an OS update, or change your menu bar settings in any way?
GUI AppleScript is heavily dependent on the way you have your screen setup... so if you remove the Dropbox icon from the menu bar for instance, this script will fail.
Also, to make it easier to read the script, you should wrap the entire thing in three grave accents ``` to preserve the formatting. I had to copy and paste into Script Debugger to be able to read it
Edit: One more thing @ikenassi, what is your macro supposed to do? Because both your click icon and set variable portions of the script are commented out, so this script really doesn’t do anything except return Dropbox's status, but doesn’t do anything with that unless you are saving that as a variable via the KM AppleScript action.
I actually don't know what was wrong with it. Yes, I've updated MacOS many times over the last few years, but this is the first time this macro broke. It might have been some security setting, but now that seems unlikely. Be that as it may, I rewrote it. This version works:
Just experimenting with the suggestion to use three grave accents:
# 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
# Updated by Ike Nassi 2020-07-14
# Updated by Ike Nassi 2021-01-29 after the last version stopped working
#
set DropBoxStatus to "Not Synced"
repeat
tell application "System Events"
tell UI element "Dropbox"
tell menu bar 2
tell menu bar item 1
set DropBoxStatus to help
end tell
end tell
end tell
end tell
if DropBoxStatus contains "Up to date" then return "Up to Date"
delay 5
end repeat
Hmm... I have an M1 but it's running a different OS than my Intel iMac but...
I haven't seen UI element used in conjunction with System Events in awhile... what if you changed that for application process "Dropbox"?
Either way, what error code if any is it returning? Can you run the script in an AppleScript editor, preferably Script Debugger (far superior to Apple's native Script Editor) to see what the issue is?
I tried that already. It makes no difference. The problem is the value of the "help" element is missing on the M1, but is present on the Intel version. Looks like the AppleScript implementation is different, somehow. My copy of script debugger immediately crash, so I upgraded it. I got this message running my script when I tried to access "help". I don't understand what it's trying to tell me.
set DropBoxStatus to "Not Synced"
tell application "Dropbox" to activate
repeat
tell application "System Events"
tell application process "Dropbox"
tell menu bar 2
-- display dialog (UI elements) as string
tell menu bar item 1
set DropBoxStatus to help
-- display dialog DropBoxStatus as text
end tell
end tell
end tell
end tell
if DropBoxStatus contains "Up to date" then return "Up to Date"
delay 5
end repeat
Can you try this AppleScript to see if it works on your M1?
----------------------------------------------------------
# Author: Chris Thomerson (@cdthomer)
#
# Current Version: 1.0 (Initial script)
# Version History: 1.0 (Initial script)
#
# Created: Monday, January 31, 2022
# Modified: Monday, January 31, 2022
# macOS: 12.1 (Monterey)
# Tags: Dropbox, Syncing
#
# DISCLAIMER
# Permission to use, copy, modify, and/or distribute this
# software for any purpose with or without fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
# THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
----------------------------------------------------------
tell application "System Events" to tell application process "Dropbox"
(*
set attNames to every attribute of menu bar item 1 of menu bar 2
set attValues to value of every attribute of menu bar item 1 of menu bar 2
*)
if value of attribute "AXHelp" of menu bar item 1 of menu bar 2 contains "Up to date" then
set dbStatus to "Up to date"
else
set dbStatus to "Syncing"
end if
end tell
dbStatus
added debugging statement. It returns "missing value" as before.
----------------------------------------------------------
# Author: Chris Thomerson (@cdthomer)
#
# Current Version: 1.0 (Initial script)
# Version History: 1.0 (Initial script)
#
# Created: Monday, January 31, 2022
# Modified: Monday, January 31, 2022
# macOS: 12.1 (Monterey)
# Tags: Dropbox, Syncing
#
# DISCLAIMER
# Permission to use, copy, modify, and/or distribute this
# software for any purpose with or without fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
# THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
----------------------------------------------------------
tell application "System Events" to tell application process "Dropbox"
(*
set attNames to every attribute of menu bar item 1 of menu bar 2
set attValues to value of every attribute of menu bar item 1 of menu bar 2
*)
if value of attribute "AXHelp" of menu bar item 1 of menu bar 2 contains "Up to date" then
set dbStatus to "Up to date"
else
-- display dialog "Huh? " & (value of attribute "AXHelp" of menu bar item 1 of menu bar 2)
set dbStatus to "Syncing"
end if
end tell
dbStatus
I've highlighted the relevant attribute we use to get sync status. As you can see, on my M1 the value is "Dropbox 140.4.1951\nUp to date". What missing value are you referring to? And what do you mean it always returns "Syncing"? For me, the only time it returns syncing is if it is indeed syncing file(s).
Well bugger.... I know Dropbox has some issues because it is still not designed to run natively on M1, but I don't recall having seen this problem before. I have no clue why it's happening but it's most definitely an issue with Dropbox as it is not supplying the normal accessibility information that it should.