7

I'm trying to get the dock and menu bar in OS X Lion to auto-hide globally. The reason I want it to do so for all programs is because I'm trying to play a game in wine, and when running in fullscreen the CPU usage goes through the roof, so while playing windowed I've always had to manually tell the dock to hide before playing.

I know about editing info.plist and LSUIPresentationMode key, but unfortunately the game launcher notices that the file has been edited and fixes it before launching. So my only choice is to make it hide for all programs before starting, is this possible? Is AppleScript even the best way to go about this? I'm still pretty new to coding on the Mac so any suggestions on how to accomplish this are appreciated.

5 Answers 5

9

You can do the dock easily. I do not know how to do the menu bar globally. I doubt it's possible. Here's a script for the dock. It will toggle it to auto-hide or not based on the current condition. Good luck.

tell application "System Events"
    tell dock preferences to set autohide to not autohide
end tell
3
  • Great, thank you for that. What I found on Google must have been outdated, as I said I've been coding for a long time but know absolutely nothing about AppleScript, which is pretty unfamiliar and certainly not based on anything I've used before.
    – jamzsabb
    Jan 21, 2013 at 19:16
  • 2
    Glad to help. Applescript is easy. It's just like other languages in that it has if statements, repeat loops, and other normal stuff. What it is for is controlling other applications. So basically if you have an application you want to control you see if the app accepts applescript commands by checking if it has an applescript dictionary of terms. If it does you can control it. You check for the dictionary under the file menu of AppleScript Editor with "Choose Dictionary". You look for your app there and if you find it you look through it at the commands you can issue to it. Simple. Jan 21, 2013 at 20:33
  • Although this used to be a good solution, it's not as good, in Mojave, what with its AppleEvent Sandboxing which asks the user for permission to send AppleEvents to "System Events" the first time that this script is run, this solution isn't as good as it used to be. @regulus6633, is there a way to bypass AppleEvents? I'm afraid that the user would "Disallow" AppleEvents and thereafter errors would happen. UserDefaults or CFPreferences maybe?
    – Kaydell
    Oct 12, 2018 at 15:08
6

For those still interested, this is a solution for those on OS X. The General Settings page now starts at the search bar where tab doesn't work. This is a work around.

tell application "System Preferences"

    --open General Settings
    activate
    set the current pane to pane id "com.apple.preference.general"
    try

        --wait for screen to boot
        repeat until window "General" exists
            delay 0.2
        end repeat
        delay 0.5
    on error error_message
        get error_message
    end try
end tell


--click the appropriate check box
tell application "System Events"
    click checkbox "Automatically hide and show the menu bar" of window "General" of application process "System Preferences" of application "System Events"
end tell
0
5

For Big Sur:

tell application "System Events"
    tell dock preferences to set autohide menu bar to not autohide menu bar
end tell
1
  • I did not expect this to be so simple, but it works. I guess that gives at least 1 reason to upgrade to Big Sur.
    – Harm
    Feb 1, 2021 at 23:46
0

This is an applescript that does it for me because it's something I really wanted to see too. I'm not sure that it'll win style points, but I call this with an Automator service and set a keyboard shortcut to it, and I haven't complained about it since.

tell application "System Events"
    tell dock preferences
        --get the properties list of the dock and set (or assign) it to our variable we'll call "dockprops"
        set dockprops to get properties
        --in our now "dockprops" list, assign our target dock property ("autohide") to the variable "dockhidestate"
        set dockhidestate to autohide of dockprops
        --the dock's "autohide" property is a boolean: it's value can only be either true or false
        --an "if statement" provides the necessary logic to correctly handle either of these cases in this one single script
        if autohide = true then
            tell application "System Events"
                tell dock preferences to set autohide to not autohide
            end tell
        else
            set autohide to true
        end if
    end tell
end tell

tell application "System Preferences"

    activate
    --  tell application "Finder" to tell process "System Preferences" to set visible to false
    set the current pane to pane id "com.apple.preference.general"

    --  The delays are necessary as far as I can tell
    delay 0.5
    tell application "System Events" to keystroke tab
    delay 0.5
    tell application "System Events" to keystroke tab
    tell application "System Events" to keystroke tab
    tell application "System Events" to keystroke space
    tell application "System Events" to key code 13 using {command down}
end tell
0

Easiest way to do it simultaniously - (WORKS ON MACOS MONTEREY, and i assume all other verions as well but i havent tried it)

tell application "System Events"
    tell dock preferences to set autohide to not autohide
    tell dock preferences to set autohide menu bar to not autohide menu bar
end tell

Application and Script Versions I made so you can just download it if you want Files

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.