Reputation: 1154
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.
Upvotes: 7
Views: 6106
Reputation: 1
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
Upvotes: 0
Reputation: 51
For Big Sur:
tell application "System Events"
tell dock preferences to set autohide menu bar to not autohide menu bar
end tell
Upvotes: 5
Reputation: 131
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
Upvotes: 6
Reputation: 1
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
Upvotes: 0
Reputation: 19032
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
Upvotes: 9