Black Lives Matter

I stand in solidarity with the Black community against racism and injustice.

Show and hide the Mac menu bar using AppleScript

Open the Script Editor application, and type in this AppleScript (adapted from this StackOverflow quesiton):

tell application "System Preferences"
reveal pane id "com.apple.preference.general"
end tell
tell application "System Events" to tell process "System Preferences" to tell window "General"
click checkbox "Automatically hide and show the menu bar"
end tell
quit application "System Preferences"

AppleScript Editor

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.

Allow Script Editor permissions

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.

Run the AppleScript from the terminal

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 Screencasts.

$ osascript /path/to/HideMacMenu.scpt

From here, it's easy to create a bash alias to make running this command even easier.

In your .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.

Conclusion

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.