
In other words, you have to stop multitasking for a couple of seconds. This means once you triggered the app, you have to let it run and not manually steal focus from System Preferences while the UI Scripting events take place. However, that said, it too is not without possible issues in that it relies on UI Scripting, meaning, it has to open System Preferences to the General settings and click the "Automatically hide and show the menu bar" checkbox and close System Preferences. After all, I double you already have an app named tm installed. As an example, name it tmb.app for toggle menu bar, the you'd press ⌘ space t m enter to trigger the AppleScript App. In lieu of a third-party app or as an Automator Service and just as a plain AppleScript app, you do have a keyboard shortcut built in by way of Spotlight, in that you press ⌘ space and the first character or two of the name you gave to the AppleScript app and then press enter. So, how about an AppleScript app you could place in the Dock, so it's readily available to click on, that will toggle the state of the Menu bar? You'd only have to add that AppleScript app to System Preferences > Security & Privacy > Privacy > Accessibility, in order for it to work. This might include apps like Alfred, FastScripts, Karabiner, Karabiner-Elements, Keyboard Maestro, etc., and having not tested these third party apps under this particular scenario I can only offer that as something to look into.
#Mac menubar countdown apple scripts code
Every app that has focus when the service's keyboard shortcut is triggered would have to be added to System Preferences > Security & Privacy > Privacy > Accessibility, in order for the service's keyboard shortcut to work.Ī possible workaround to the second point above would be if there's a third-party app that can be globally set to trigger the Automator Service work flow (or the AppleScript code as an AppleScript script or app not using an Automator Service).

You'd have to assign the Automator Service a keyboard shortcut that does not interfere with an existing shortcut in every app that might have focus when you triggered the service's keyboard shortcut.However, the longer answer is, while it's technically and natively possible to create an Automator Service workflow that gets assigned a keyboard shortcut to hide/unhide the Menu bar in OS X 10.11 and later, including the current macOS, it's not without its issues. You asked, " Can a shortcut be created to toggle menubar visibility (that would persist, as the dock's does)?" and the short answer is, yes.
