Show and hide the Mac menu bar using AppleScript
tell application "System Preferences"reveal pane id "com.apple.preference.general"end telltell application "System Events" to tell process "System Preferences" to tell window "General"click checkbox "Automatically hide and show the menu bar"end tellquit application "System Preferences"
This AppleScript will toggle automatically hiding and showing of the menu bar. You can test this by clicking the play button to run the script.
You may need to allow Script Editor permissions to control your computer.
You can do this by going to
System Preferences → Security & Privacy, select the Privacy tab at the top, then select Accessibility in the left-hand menu.
Click the lock and input your password to make changes, then check the box next to Script Editor. If Script Editor is not in the list, add it using the plus button.
You can run this script from your terminal by typing
osascript followed by the path to your AppleScript. I saved this AppleScript in a directory called
$ osascript /path/to/HideMacMenu.scpt
From here, it's easy to create a bash alias to make running this command even easier.
.bash_profile add an alias similar to this one:
alias hidemenu="osascript /path/to/HideMacMenu.scpt"
Restart your terminal or source your
.bash_profile and type
hidemenu to test it out. You may need to allow your terminal application permissions to control System Events.
Using AppleScript, we can automate common tasks like adjusting system settings. I find this task especially useful when preparing for live streaming or screen recording. In the future, I'd love to bundle this up with other screen recording setup, like adjusting my screen resolution and then creating a custom hotkey to execute all of the commands in one go.