if menu bar is visible

I have the general menu bar “Automatically hide and show” (Preferences / General)

With that option selected, when the mouse gets closer of the top of the screen, the bar is visible, when it goes below the bar, the bar is hidden

Can AppleScript know when the bar is hidden and when is show? or can AppleScript know if the mouse is close to the top border of the screen?

Something like:

if menuBar is visible
– do something
else
– do something else
end if

One way is the following script. Run script, move the mouse pointer (during the delay) to see what happens. Although, I do not see any practical benefit in this.


use framework "AppKit"
use scripting additions

delay 5 -- This delay is for testing purposes. Use it to move (or not) mouse on top of screen

set |mouseLocation| to current application's NSEvent's mouseLocation()
tell application "Finder" to set theDesktopBounds to bounds of window of desktop
set |mouseLocation| to {|mouseLocation|'s x, (item 4 of theDesktopBounds) - (|mouseLocation|'s y)}

if (item 2 of |mouseLocation|) < 22 then
	say "menu bar is visible" using "Alex"
else
	say "menu bar is hidden" using "Alex"
end if

@KniazidisR

Thank you very much. It works very well. But it only works one moment in time. Is it possible to work always?

I have created a small application with Xcode - AppleScript. I would like that when the menu bar appears, the screen that I have created disappears. and when the menu bar is not visible, my window comes again.

In xCode, event-driven code building can have hundreds of ways to achieve the same. You will likely be helped if you submit your question to the xCode forum. But you should provide more information about what you do.

Ok. Thank you