Skip to content

Instantly share code, notes, and snippets.

@lacostenycoder
Created December 13, 2022 19:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lacostenycoder/1de15cb0f8a6b440da830ac126d0bc32 to your computer and use it in GitHub Desktop.
Save lacostenycoder/1de15cb0f8a6b440da830ac126d0bc32 to your computer and use it in GitHub Desktop.
Toggle showing or hiding MacOS Dock
#!/usr/bin/ruby
# idea from https://gist.github.com/mattitanskane/43eb9a4b59f16ce46d2a6dbf6c02b87d
if ['-h','--hide'].any?{|h| h == ARGV[0]}
# Hide Dock
shell = <<~BASH
defaults write com.apple.dock autohide -bool true && killall Dock
defaults write com.apple.dock autohide-delay -float 1000 && killall Dock
defaults write com.apple.dock no-bouncing -bool TRUE && killall Dock
BASH
good = 'hidden'
end
if ['-s','--show'].any?{|h| h == ARGV[0]}
# Restore Dock
shell = <<~BASH
defaults write com.apple.dock autohide -bool false && killall Dock
defaults delete com.apple.dock autohide-delay && killall Dock
defaults write com.apple.dock no-bouncing -bool FALSE && killall Dock
BASH
good = 'shown'
end
if good
system(shell)
puts "Your dock is now #{good}!"
else
puts 'Invalid argument. Valid args: -h, --hide, -s, --show'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment