Now that this forum will let me post more than one image, I’ll ask again more concisely, hoping someone will help me.
I run a short AS from Keyboard Maestro to change the Stream Deck profile. It worked until a new Stream Deck version moved the list of profiles one level deeper in its menu bar hierarchy. Here’s the script. (Sorry for the image–this forum’s help section says to use the AppleScript button above the text box, but I don’t see it.)
I think I need to change the “tell menu 1 of menu bar item 1 of menu bar 2” line.
Here are the old and new menu structures:
UI Browser says this is the element path all the way down to the item I want to click:
From this, I constructed:
tell menu 1 of menu item “Stream Deck XL” of menu 1 of menu bar item 1 of menu bar 2
But it doesn’t work. Am I getting close?
Thanks,
Russell
Menu Items on the status bar (on the right side of the menu bar), their submenu don’t exists until the menu bar item is clicked.
tell application "System Events"
tell process "Stream Deck"
click menu bar item 1 of menu bar 2
delay 0.5 -- give it time to draw menu
click menu item "LR-Home" of menu 1 of menu item "Stream Deck XL" of menu 1 of menu bar item 1 of menu bar 2
end tell
end tell
or a fancier version with a timeout
tell application "System Events" to tell process "Stream Deck"
click menu bar item 1 of menu bar 2
repeat with i from 100 to 0 by -1 -- will loop for 10 seconds
if exists menu 1 of menu bar item 1 of menu bar 2 then exit repeat
delay 0.1
end repeat
if i = 0 then return -- timed out
click menu item "LR-Home" of menu 1 of menu item "Stream Deck XL" of menu 1 of menu bar item 1 of menu bar 2
end tell
Thanks for the response (Robert?).
I tried both of your versions and the SD profile didn’t change. But the delay seems like a good idea. I also looked at the "click menu item “LR-Home…” line, and it appears to track the element path UI Browser specified.
Do you have a Stream Deck with the software version 6.4.1 that came out a few days ago? Do the scripts work on your Mac? Just want to be sure there’s not something weird with my system that would keep a good AS from working. (However, my old script worked fine on the SD version without the profiles in a sub-menu.)
By the way, where is the Applescript button above this text I’m writing now? It’s not on the tool bar with bold, italic, link, etc. Your example code is nicely displayed!
Best,
Russell
Sorry, I don’t have a Stream Deck so I can’t test.
When you have some code you surround it with 3 ticks.
The tick (`) is the character on the key with the tilde (~) on a US keyboard
So put 3 ticks on a line by itself, then the code followed by 3 ticks again on a separate line.
You should check to make sure the name of the App didn’t change its spelling including spaces. That could be why you can’t reference the menu
I’m making some progress. This script displays the second-level “Stream Deck XL” menu, showing the list of Stream Deck profiles:
tell application "System Events"
tell process "Stream Deck"
click menu bar item 1 of menu bar 2
delay 0.1 -- give it time to draw menu
click menu item 7 of menu 1 of menu bar item 1 of menu bar 2
end tell
end tell
Interesting that while menu item “Stream Deck XL” didn’t work, using “menu item 7” did work.
Now, I need to click an item (LR-Home) on that list of profiles. So, I modified the above script like this:
tell application "System Events"
tell process "Stream Deck"
click menu bar item 1 of menu bar 2
delay 0.5 -- give it time to draw menu
click menu item "LR-Home" of menu 1 of menu item 7 of menu 1 of menu bar item 1 of menu bar 2
end tell
end tell
Unfortunately, this one doesn’t execute “click menu item “LR-Home” of menu 1 of menu item 7 of menu 1 of menu bar item 1 of menu bar 2”
I tried changing “LR-Home” to menu item 16, but that didn’t help.
As a reminder, this is the element path reported by UI Browser:
There must be something about the new Stream Deck version that’s preventing normal Applescript UI scripting from working.
Do you know of any way to have AppleScript click an item in a menu what is currently displayed?
run this to see what the actual name of the menu item is
tell application "System Events"
tell process "Stream Deck"
click menu bar item 1 of menu bar 2
delay 0.5 -- give it time to draw menu
set mname to name of menu item 7 of menu 1 of menu bar item 1 of menu bar 2
end tell
end tell
display alert "\"" & mname & "\""
Also if the click command doesn’t work, you can try “perform action” like so
tell menu item "LR-Home" of menu 1 of menu item 7 of menu 1 of menu bar item 1 of menu bar 2 to perform action "AXPress"
ALSO
I might be on to something. You might need to click also on the submenu to get it to display before you can click it like so…
tell application "System Events" to tell process "Stream Deck"
click menu bar item 1 of menu bar 2
repeat with i from 100 to 0 by -1 -- will loop for 10 seconds
if exists menu 1 of menu bar item 1 of menu bar 2 then exit repeat
delay 0.1
end repeat
if i = 0 then return -- timed out
click menu item 7 of menu 1 of menu bar item 1 of menu bar 2
repeat with i from 100 to 0 by -1 -- will loop for 10 seconds
if exists menu 1 of menu item 7 of menu 1 of menu bar item 1 of menu bar 2 then exit repeat
delay 0.1
end repeat
if i = 0 then return -- timed out
click menu item "LR-Home" of menu 1 of menu item 7 of menu 1 of menu bar item 1 of menu bar 2
end tell
I think that Status Bar menu Apps don’t load sub-menus into memory until parent menu is clicked on
In case anyone’s following this, the problem was solved by a smart person on Late Night Software’s Script Debugger forum:
tell application "System Events"
tell process "Stream Deck"
click menu bar item 1 of menu bar 2
delay 0.5 -- give it time to draw menu
click menu item 7 of menu 1 of menu bar item 1 of menu bar 2
delay 0.5
click menu item "LR-Home" of menu 1 of menu item 7 of menu 1 of menu bar item 1 of menu bar 2
end tell
end tell
This got my drill-down to the second-level Stream Deck menu working.
Isn’t that the same as my script above. But mine has a more sophisticated delay system with a timeout function.
You’re right! I didn’t notice your second script that opened the submenu. My apologies!
And your timer is better-- I’ll include that.
Thanks again,
Russell