Can I use Applescript+Accessibility to determine if the Menu Bar is visible? Obviously I can use Find Image, (probably on the Apple logo) but I was curious if A+A might be more efficient. I did spend at least a half hour asking ChatGPT about this but it couldn't find a working answer, at least not for Tahoe.
This script seems to work for testing Menu Bar visibility.
tell application "System Events"
if autohide menu bar of dock preferences is false then
return {"OK"}
end if
end tell
What version of macOS do you have? I've been trying for a half hour to get that to work on Tahoe. Could it be a permissions issue for me?
Sequoia. I made it off of this other script I found for toggling Menu Bar visibility.
tell application "System Events"
if autohide menu bar of dock preferences then
set autohide menu bar of dock preferences to false
else
set autohide menu bar of dock preferences to true
end if
end tell
Here's a defaults read command that seems to work on Tahoe:
defaults read NSGlobalDomain _HIHideMenuBar
I tried searching for this on my own, but had no luck. So I fed @NaOH's script to an AI, and asked it for the corresponding defaults command. It appears it got the right answer, as this worked perfectly when I tested it.
See my follow-up: You need to have hidden the menu bar once for this command to work, at least in macOS Tahoe.
-rob.
Neither griffman's nor NaOH's ideas work for me. In the case of griffman, I get the following error:
myname@Mac ~ % defaults read NSGlobalDomain _HIHideMenuBar
2025-11-17 23:44:13.730 defaults[58199:1009919]
The domain/default pair of (kCFPreferencesAnyApplication, _HIHideMenuBar) does not exist
The dock's autohide flag has nothing to do with whether the Menu Bar is visible. For example, the Dock could either be in autohide or not in autohide while the Menu Bar is visible. So they aren't related.
cc @griffman to make certain he sees Airy's last comment.
The hide/show preference for the Menu Bar is part of the Dock preference. The script I found for toggling Menu Bar visibility that I posted above works here on Sequoia, but I wouldn't know if things have changed with Tahoe.
Ah jeez, brain dead me, so sorry! I was working on my laptop, then moved to my desktop. Desktop is still Sequoia.
Sorry;
-rob.
Correction:
This does work in Tahoe, but you have to have hidden the menu bar at least once. Once you've done that, that sets the value in the global domains file, and it can then be read. (You cannot set it to 1 to hide the menubar, however.)
-rob.
What does that mean? I hide it every 10 minutes when I'm using a full screen app.
Are you talking about some different kind of hiding? Can you elaborate?
In Sequoia, so maybe the same in Tahoe...
System Settings > Control Center > Automatically Hide and Show The Menu Bar
Set it to Always then change it to whatever is your long-term/standard preference.
That fixed my Terminal "error" message and made the AppleScript return a value. Thanks. I have no idea how you found that out, other than you must be a very smart person.
Even so, in both cases the code claims that the Menu Bar is visible when it's NOT visible, at least in the cases of full screen apps. That means these commands are returning the WRONG values. As stated in my first sentence, I want to know how to "determine if the Menu Bar is visible". If an app is full screen, the AppleScript (and the Terminal command) still return a value indicating that the menu bar is present even though the menu bar is NOT visible. That's the problem. I don't want to know about some theoretical internal macOS setting, instead I want to know if the menu bar is actually visible which is a completely different thing.
I presume there is no solution to my problem. Thanks for trying.
P.S. I confess that I was confusing the autohide of the dock with the autohide of the menu bar. It's easy to understand my confusion since the AppleScript refers to both the dock and the menu bar in the same command.
Are we, perhaps, conflating whether auto-hide is enabled with whether the menu bar is currently visible?
Not so fast! A quick look at menu bar properties in different states suggests that, at least in a single- or horizontal two-screen setup, the y coordinate of position is a negative number when the bar is hidden, 1 when it is visible. So:
tell application "System Events"
tell process "Control Centre"
if item 2 of (get position of menu bar 1) < 0 then
return "Hidden"
else
return "Visible"
end if
end tell
end tell
Pop that in the script section of an "If" action and see how you get on.
I get no result. Neither Hidden nor Visible.
I think that's what I've been trying to say several times.
Control Centre stuff got moved around in Tahoe, so the Sequoia reference is probably wrong. I'll see what I can find...
And... Nothing. Sorry, @Airy.
TBH, a quick image detect on the tiny portion of the screen that may/may not contain the Apple menu item may well be faster than instantiating an AS environment! My main reason for testing programmatically would be to avoid the usual image issues like dark/light mode and so on -- and I don't think you can OCR the ...
If I'm understanding correctly, the question is as much about if Full Screen mode is active as anything. If that's the case, what about checking if View > Exit Full Screen is an available menu item (note that's Sequoia wording, maybe different in Tahoe)?
Or checking the dimensions of the frontmost window?
You said nothing about full screen apps in your original problem description:
So that's why all the solutions provided were focused on checking the state of the menu bar, and paid no attention to its visibility when an app was running in full screen mode. Had you included that in the first post, the answers probably would have been different.
I can see why the value doesn't change when an app is full screen, because (it seems to me) that state is temporary, so Apple doesn't update the setting for the visibility of the menu bar.
-rob.
Except you can auto-hide/show the menu bar when not in Full Screen, too.
Not knowing why @Airy wants to do this (KM's "Select a Menu Item" works whether the menu bar is displayed or not, for example) makes it difficult to suggest other potential approaches.
And, unfortunately, SCREENVISIBLE() always thinks the menu bar is there -- a failing in Apple's underlying APIs, IMO.