.
Looks like software “Bartender” has solved this problem.
Using status menu items (right side of menu bar) takes endless mousing around.
So, now I’m looking at “Bartender” – on trial.
Works fine, but interface is a jumble of preferences.
I’m spoiled by the clean, straight-forward, interface of KM.
I don’t want to buy “Bartender” … much prefer to stay within KM.
If KM solves this problem, I suggest offering a “KM-Pro” edition with that feature, for a premium price.
How much premium?
Double the current price; I’d buy immediately.
For anyone who wants to look at "Bartender, there’s a free trial at: Macbartender.com
The process name is “Flux” (not “f.lux”). This script will open the f.lux menu:
tell application "System Events"
tell application process "Flux"
tell menu bar 1
tell menu bar item 1
perform action "AXPress"
end tell
end tell
end tell
end tell
Now, the more important question:
How do you know the names of process?
If there is an easy and direct way to know those names, then many users of KM can use the script you provided.
For example:
To open menu bar item, "Network Preferences," with drop down menu, what is the name of that process, and how do you know it?
In "Activity Monitor" I found "Network Preferences".
But plugging that into the script does not work.
Screen print below:
Top half shows Network Preferences, which I opened by clicking.
Bottom half shows the script used in KM.
But this script does not open Network Preferences' drop down menu.
What is the best way to find correct names of processes?
Or, perhaps your answer will be, "learn Apple Script".
In general the Activity Monitor gives you the process name. However I don’t have the Networks Preferences menulet as shown in your screenshot, so I can’t say much in that particular case.
With the System’s menulets the process name is a bit different. I can for example open the Wi-Fi menulet with this:
tell application "System Events"
tell application process "SystemUIServer"
tell menu bar 1
tell (first menu bar item whose description starts with "wi-fi")
perform action "AXPress"
end tell
end tell
end tell
end tell
So, you could try to replace “wi-fi” here with “network”.
Keep in mind that certain System Preferences (for example Network Preferences!) are directly scriptable. That means you can do things without clunky UI scripting. You find the scriptable System Preferences and examples here.
It will output the descriptions of all enabled system menulets. For example: Notification Center, Siri, time machine, system sound volume, AppleScript, bluetooth, text input, Clock, Wi-Fi, four of four bars, ….
In the output look for a description that is likely to be the one of the Network menulet. In my case it’s Wi-Fi, four of four bars, in your case it’s probably different and may be something like Ethernet… or Connected… etc.
Then just paste the description (or the first part of the description) into the AppleScript from the post above.
Like this (the red part is where the correct description goes):
[…]
tell (first menu bar item whose description starts with "<description here>")
[…]
[quote="peternlewis, post:2, topic:4988, full:true"] ... use a Click at Found Image, although even that can be difficult as they often animate or change icons based on various states.
[/quote]
Thank you, Peter.
Now I have started using "Click at Found Image" to access Menulet Apps.
It works very well.
Solves 90% of this problem quickly and easily, entirely within KM, without any AppleScripting.
Besides the Finder menu bar, it also works within applications, such as Firefox.
The 10% remaining -- with changing icons -- can mouse and click.
I'm content with that.
So no need for a utility like "Bartender" to access menu bar items.
I'd never used "Click at Found Image" function before, so was unsure where to start.
To help others get started, here is an example that works.
(This example opens Firefox add-on, "SiteDelta".)
Menulets like the Network one are tricky because the description changes in function of what is displayed. Another approach is getting them by item number. But this isn’t fix either.
I too am attempting to select a menu item from a menulet app, but I'm having trouble getting it to work using the advice in this thread.
In my case, the menu I'm trying to access is for Backblaze (the menu appears to be named 'bzbmenu' based on what I see in Activity viewer). I want to select the item 'Backup Now'.
I was able to get it to work using Found Image, but I can't use this method because I want the script to trigger at a time when my display will be asleep (but not my computer).
I tried using this applescript:
tell application "System Events"
tell application process "bzbmenu"
tell menu bar 1
tell menu bar item 1
perform action "AXPress"
end tell
end tell
end tell
end tell
Running this did open the menu, but did not select an item from the menu. (The menu item I want to select is 'Backup Now'.) It just opened the menu and a few seconds later the output 'missing value'.
tell application "System Events"
tell application process "bzbmenu"
tell menu bar 1
tell menu bar item 1
perform action "AXPress"
end tell
end tell
repeat 2 times
key code 125 -- Down Arrow
end repeat
key code 36 -- Return
end tell
end tell
Forget my old script from above. This one runs faster:
tell application "System Events"
tell application process "bzbmenu"
tell menu bar 1
tell menu bar item 1
try
with timeout of 0.1 seconds
perform action "AXPress"
end timeout
end try
end tell
end tell
end tell
end tell
do shell script "killall 'System Events'"
tell application "System Events"
repeat 2 times
key code 125
end repeat
key code 36
end tell
It’s an ugly hack to bypass the strange delay (OS bug?) as already mentioned here.
If you don’t see any delay with my previous script then… use the previous script.
To test this, I added a 'Play Sound' action before and after the script, so I could tell if it was working even when my display is asleep.
When using the 'At time' trigger, and the display asleep, I heard the first sound, then the second sound after a 2 minute delay. However the menu item was not selected and the backup did not begin. When the screen was awake, the result was the same. I did not see the Backblaze menu open, I just heard the two sounds with a 2 minute delay.
Strangely, when I ran the macro manually by clicking the 'Try' button, I heard the first sound, then I saw the menu open, select the correct 'Backup' menu item, then the second sound played. In this case the backup was successfully initiated.
So it seems that it almost works, but unfortunately not under the conditions I need it to, namely with the 'At time' trigger and the screen asleep.
As mentioned by @peternlewis in another topic, you can't use UI scripting or KM UI actions when the Mac is asleep.
So, you need to first wake the Mac before running the script/macro. You probably need an AppleScript set to execute at a given time. Do some searching on "AppleScript to wake Mac", or similar.
Yes, thank you. I do understand that. To clarify, my computer is set to never sleep. It is only the display that is asleep. I can tell that the computer is awake because I can hear the sounds executed by the macro and see the power light remains dimly illuminated (not pulsing).