Skip navigation

Activating Dock auto-hide feature from command line

1126 Views 7 Replies Latest reply: May 11, 2013 9:50 AM by twtwtw RSS
Rob de Jonge Level 3 Level 3 (510 points)
Currently Being Moderated
May 10, 2013 2:58 AM

I'm trying to put a script together that enables autohide when I use my laptop as the main screen, and disable when it's connected to an external display. I've got the detection bit working now. But what I can't seem to get working, is turning the autohide feature on and off.

 

I find this all over the web ...

Hide-command: defaults write com.apple.Dock autohide -bool TRUE; killall Dock

Show-command: defaults write com.apple.Dock autohide -bool FALSE; killall Dock

 

And the hide-command works.

But the show-command seems to not be working for some reason.

 

Also, my desktop flashes when I run either command.

When I hit Opt-Cmd-D, this doesn't happen.

 

Any recommendations on how I can trigger that shortkey?

Or other thoughts on how to make this work?

MacBook Air, OS X Mountain Lion (10.8.3), 2GHz i7, 8GB RAM, 256GB SSD
  • Mark Jalbert Level 5 Level 5 (4,385 points)

    This may be handled better with AppleScript.

     

     

    tell application "System Events" to set the autohide of the dock preferences to true
     
    tell application "System Events" to set the autohide of the dock preferences to false
    
  • MrHoffman Level 6 Level 6 (11,695 points)

    The display command is:

     

    defaults read com.apple.Dock autohide

     

    That's a read, and there's no need to restart the Dock.

     

    The following (intentionally) isn't complete, but is pretty close (as I don't want to kill my Dock right now, due to an unrelated factor)...

     

    if [[ `defaults read com.apple.Dock autohide` = 0 ]] ; then defaults write com.apple.Dock autohide 1 ; fi ;

  • BobHarris Level 6 Level 6 (12,505 points)

    Try "Control Plane". It is suppose to be a Marco Polo descendent.

  • Mark Jalbert Level 5 Level 5 (4,385 points)
    Hi Rob, I have a few suggestion for you
    
    if [ `system_profiler SPDisplaysDataType | grep 'Cinema\|Thunderbolt' | wc -l` -eq "1" ]; then
    
    # loose the backtick and write your command substition like $(command|command|.....)
    
    if [ $(system_profiler SPDisplaysDataType | grep 'Cinema\|Thunderbolt' | wc -l) -eq "1" ]; then
    
    # doesn't that read better
    
    
    # Any time that I pipe more that once in a statement, 
    # the little voices inside my head tell me there must be a better way
    
    if [ $(system_profiler SPDisplaysDataType | grep -c 'Cinema\|Thunderbolt') -eq "1" ]; then
    
    # All non-Apple command line tool produce a
    # non-zero exit status if they fail. So the following
    # should work without producing a sub-shell (faster execution).
    # You don't have to test "[" either.
    
    
    if system_profiler SPDisplaysDataType | grep -q 'Cinema\|Thunderbolt'; then
    
    # Does the following write to the dock preference file every 10 seconds
    # if the display is not connected?
    
    
    else
      osascript -e "tell application \"System Events\" to set the autohide of the dock preferences to true"
    
    # May be something like this if it is
    
    else
         osascript <<-EOF
              tell application "System Events"
                   set results to get the autohide of the dock preferences
                   if resutls = false then
                        set the autohide of the dock preferences to true
                   end if
              end tell
    EOF
    
    
    
    
    
    
    
  • twtwtw Level 5 Level 5 (4,580 points)

    try this:

     

    osascript -e 'tell application "System Events" to set autohide of dock preferences to not (autohide of dock preferences)'

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.