I use this applescript to click a custom menubar icon configured in BTT:
try
tell application "System Events"
tell application process "BetterTouchTool"
tell menu bar item 2 of menu bar 2
click
end tell
end tell
end tell
on error the_error
return the_error
end try
It works good in applescript, but if I use it as an action in BTT, I get this error:
System Events got an error: Can’t get menu bar 2 of application process "BetterTouchTool". Invalid index.
The script isn't working for me, neither with the script editor nor with BTT. If I understand you correctly, this sequence should, however, accomplish the same task.
The applescript is not clicking a menu bar item of the titles menu. It clicks an icon item of the menubar, like the icon of Control Center. But in my case, the applescript clicks a custom menubar icon configured in BTT.
You can test the following applescript. It only changes the menu bar item number (1 instead of 2). This one clicks the default status bar icon of BTT.
try
tell application "System Events"
tell application process "BetterTouchTool"
tell menu bar item 1 of menu bar 2
click
end tell
end tell
end tell
on error the_error
return the_error
end try
I have the menu bar configured as "hide always automatically" in macOS System Configuration.
The "Click Menu Bar Status Item" action in BTT only works for me if the menubar is visible.
The applescript you wrote works fine if I run it from an external applescript, but not if I run it inside BTT. Can you run it inside BTT with menu bar hidden?
I have my main menu bar set to hide automatically in macos system configuration.
question 1 - The BTT action "click menu bar status item" doesn't work when the main menu bar is hidden. Is it possible to make it work even the manubar is hidden?
question 2 - I use this applescript to click a custom menubar icon configured in BTT:
try
tell application "System Events"
tell application process "BetterTouchTool"
tell menu bar item 2 of menu bar 2
click
end tell
end tell
end tell
on error the_error
return the_error
end try
It works good in external applescript, but if I use it in a BTT action, I get this error:
System Events got an error: Can’t get menu bar 2 of application process "BetterTouchTool". Invalid index.
Why I get this error and what I should do to fix it?
If you just want to trigger the actions assigned to a custom menubar item in BTT, the easiest solution would be to use execute_assigned_actions_for_trigger. The required UUID of the trigger can be received by right-clicking the custom menu trigger in BTT.
tell application "BetterTouchTool" to execute_assigned_actions_for_trigger "69983672-05EF-4B01-9499-EEAB41D00917"
Apple Script is a bit limited/complicated when doing UI-scripting in the app that is executing the script.
I can't think of a good way right now. However I think it makes sense to offer showing that menu as an action in BTT - then people could also easily replace the BTT menubar icon with a custom one.
I'll have a look!