Wednesday, January 06, 2010

How to restart a hung Finder in Mac OS/X without rebooting


Warning this is HIGHLY UNAUTHORIZED. Proceed at your own risk.
So: save everything first before going on.

Okay - to do this, it's pretty basic. We're actually not sending it the kill signal, instead telling it to restart itself or in unix signal parlance: SIGHUP. I learnt this doing some BSD coding on HP/UX systems years ago.

So first, we need the Finder's pid. This will get it:
ps -e | grep Finder | grep -v grep | cut -c1-6

And then pass that to the kill command with -sighup switch:
kill -sighup `ps -e | grep Finder.app | grep -v grep | cut -c1-6`

This will clobber Finder and it will reopen fresh(ish) as a daisy.

Put it in a script for reuse call this restartfinder.sh
#!/bin/bash
kill -sighup `ps -e | grep Finder.app | grep -v grep | cut -c1-6`
chmod +x restartfinder.sh

And you're done.


No comments: