Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Restart the dock script Desktop
[Editor's note: See the comments for a better solution, as well as a GUI-based way of doing this]

Sometimes the desktop will do something stupid - like leave some of the 'poof' effect on the screen or whatever else. The best thing to do is just restart it. Killing it will make it automatically restart. Here's a little unix script to find it's process ID & kill it:
DOCKPID=`ps aucx| grep Dock | grep -v Server | cut -d ' ' -f 4-5`
Type this script in your favorite editor (command line or GUI), save it (as PLAINTEXT) to a file, say Desktop/dock.restart. Then, make it executable by doing this in a terminal:
chmod +x dock.restart
Then, double click it in the finder. It'll ask you to choose an application to use to run it. Select Terminal as the program to run it. You'll probably have to make it show you all applications in order for that to be selectable.

After that, just double click it whenever the dock is being stupid!!
  • Currently 4.33 / 5
  You rated: 3 / 5 (3 votes cast)

Restart the dock script | 11 comments | Create New Account
Click here to return to the 'Restart the dock script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Better technique
Authored by: wejdoane on Apr 22, '01 04:14:13PM

That approach depends on knowing the number of spaces (delimiters) in the output. That will differ based on the username, process id, etc.

A simpler approach is to use awk

kill `ps -acx | grep Dock$ | awk '{print $1}'`

and to store that in an alias or an executable file in the application search path.

[ Reply to This | # ]
As an alias...
Authored by: robg on Jul 29, '02 08:45:06AM
In trying to sort through a similar hint submitted by Kevin B., we were having some trouble making versions of these aliases function on my machine. After much back and forth, Kevin came up with a quoting technique that worked for me. Applied to the above command, it looks like this:
 % alias kdock kill '`'"ps -acx | grep Dock$ | awk '{print "\$1"}'"'`'
If you add this to your alias file, then a simple "kdock" will kill the Dock upon request. -rob.

[ Reply to This | # ]
As an alias...
Authored by: aranor on Jul 29, '02 04:38:38PM
An even better version, which is a slightly modified version of the hint I actually submitted, is the following:
alias kdock kill '`'"ps -xaco pid,command |
  egrep -x '[[:space:]]*[[:digit:]]+ Dock' | awk '{print "\\$1"}'"'`'
(split into 2 lines for easier viewing) This will match only the dock and nothing else, whereas the other 2 methods could match something that's just similarly named.

[ Reply to This | # ]
As an alias...
Authored by: aranor on Jul 29, '02 04:40:43PM
Gah! The dreaded slashes bug strikes again! The preview made it look correct, but the submission had an extra slash. I'll attempt to post the code again. If it doesn't work, just remember that it's supposed to be one slash before the $1.
alias kdock kill '`'"ps -xaco pid,command |
  egrep -x '[[:space:]]*[[:digit:]]+ Dock' | awk '{print "\$1"}'"'`'
(split into 2 lines for easier viewing)

[ Reply to This | # ]
Restarting the Dock..
Authored by: Anonymous on Apr 22, '01 04:19:04PM

I think a little easier way is to simply go to the Process Viewer. Find the line the says Dock on it and click once on it. Then go up to Processes and select Quit Process. That is it.

The dock will disappear then return and still have all your apps highlighted as before.

I have only done this a few times but it has worked. In fact I just quit the dock just to see if this way still works and It does. You never know now that we are getting updates from Apple if what you did 2 weeks ago still works.

[ Reply to This | # ]
Even Easier Way...
Authored by: Anonymous on Apr 22, '01 05:47:20PM

I think that the easiest as well as safest way to do this is to make an applescript like this one:

tell application "Dock"
end tell

and save it as an application. This way you never have to go to the command line. This will obvioulsy not work it the Dock is frozen, but it will if it is acting flaky (such as not opening windows when you click on them).

[ Reply to This | # ]
Even Easier Way...
Authored by: _merlin on Apr 22, '01 06:23:05PM

An AppleScript is the best way to do it. It kills the Dock as politely as possible. The AppleScript will tell the Dock to clean up and quit, the kill command will send it an interrupt, or terminate signal. Forcing it to quit is the same as killing it. You can make the AppleScript even simpler than in you had it. THis will work, and it's only one line:

tell application "Dock" to quit

No more end tell :-)

Vasantha Crabb

[ Reply to This | # ]
Even Easier Way...
Authored by: ascorbic on Apr 24, '01 10:27:47AM

Kill, without any argument, sends a -TERM signal, which is a graceful terminate. The equivalent of force quit is the signal -KILL.

[ Reply to This | # ]
Even Easier Way...
Authored by: _merlin on Apr 24, '01 10:46:39PM

A TERM signal causes the NSRunLoop object to exit from the main event loop immediately. This does not allow the application delegate to clean up before the task terminates. This can cause corruption of preference files. AppleScript will send a DO message to the NSApplication telling it to clean up and exit.

[ Reply to This | # ]
Which completes my script!
Authored by: thinkyhead on Apr 24, '01 01:52:02AM
Here's a script I call mineffect that lives in my ~/bin folder and can be called up from the Terminal. It makes use of this tip (thank you!!) to change the minimization effect for windows and restarts the Dock to make it happen. Use it to show off the funky effects in MacOS X to your mom!

# mineffect - suck, scale, or genie please


if [ "${effect}" = "suck" ] || [ "${effect}" = "genie" ] || [ "${effect}" = "scale" ]; then
defaults write mineffect $effect
kill `ps -acx | grep Dock$ | awk '{print $1}'`
echo "mineffect: illegal option -- ${effect}"
echo "usage: mineffect genie|scale|suck"

(Now if only the Dock would stick to the right side!)

[ Reply to This | # ]
Restart the dock script
Authored by: davidtrzcinski on Jun 28, '11 10:52:10PM

An updated version if anyone is interested (this is compatible with Snow Leopard and Lion) is :

kill $(ps -xaco pid,command | egrep -x '[[:space:]]*[[:digit:]]+ Dock' | sed -e 's/Dock//g' -e 's/ //g')

it could probably be cleaned up using awk instead of sed, but still..

[ Reply to This | # ]