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

Auotmatically restart the pasteboard server System
I may be an unusual case, but I have a repetitive problem with Apple's Paste Board Server (pbs) dying on a semi-regular basis. The main symptom is the inability to copy and paste between applications. Logging out or rebooting will fix the problem every time, but a less disruptive solution is to spawn a new copy of /System -> Library -> CoreServices -> pbs. Some apps will connect to the new server automatically, though many (notably Firefox and TextEdit) need to be quit and restarted before they start working normally again.

How can you tell if pbs is dead? Open a Terminal window and run:
ps x | grep pbs
If pbs is dead, you'll see something like:
  350  ??  Z      0:00.00 (pbs)
22200 std  R+     0:00.01 grep pbs
If pbs is alive, you'd see:
  350  p4  S      0:00.29 /System/Library/CoreServices/pbs
22200 std  R+     0:00.01 grep pbs
If you see (pbs) in parentheses, it's dead! Zombied to be technical. If you see the full path to pbs listed out, then pbs is running fine. If you see both, then chances are you've already restarted pbs manually at some point since you last logged out or rebooted.

If your pbs is dead, you can starte a new one. Just open a Terminal window and type:
nohup /System/Library/CoreServices/pbs &
The nohup keeps pbs running even after you close the current Terminal window. I got sick of restarting pbs myself, so I came up with the following script -- I named it newpbs, and keep it in /usr/local/bin:

NEEDNEWPBS=`ps x | grep /System/Library/CoreServices/pbs | grep -v grep ; echo $?`

if [ "$NEEDNEWPBS" == "1" ] ; then
  echo "PBS is dead.  Starting a new one..."
  nohup /System/Library/CoreServices/pbs > /dev/null &
  osascript -e "tell application "Finder" to display dialog \
  "Paste Board Server died and was restarted at `date`" \
  buttons {"OK"}" > /dev/null &
newpbs checks to see if there's a non-zombied copy of pbs running. If there isn't, it starts a new one and displays a dialog to let you know what happened. You can always comment out or remove the osascript line if you're rather not get the pop-up. In order to check for pbs' death every five minutes, I added this script to my crontab by running crontab -e, and adding the following line:
*/5 * * * * /usr/local/bin/newpbs
While I'm still trying to track down the process that's killing my pbs, at least this gives me some added convenience.
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)

Auotmatically restart the pasteboard server | 3 comments | Create New Account
Click here to return to the 'Auotmatically restart the pasteboard server' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Minor improvement
Authored by: rohanl on Dec 15, '04 04:09:41AM
You can remove the need for the second grep by using a common trick. If you place a single character of your pattern in [] it makes no change to the matching, but will no longer match against itself. eg. change:

NEEDNEWPBS=`ps x | grep /System/Library/CoreServices/pbs | grep -v grep ; echo $?`

NEEDNEWPBS=`ps x | grep "/System/Library/CoreServices/pb[s]" ; echo $?`

[ Reply to This | # ]
Use logger
Authored by: rohanl on Dec 15, '04 04:22:16AM
Less intrusive than a dialog, is to use logger(1) to log when pbs dies. If you replace the osascript line with:

/usr/bin/logger "Paste Board Server died and was restarted at `date`"
By default, this will just go into /var/log/system.log If you want it a bit more obvious you can make it show up in the console too with:

/usr/bin/logger -p err "Paste Board Server died and was restarted at `date`"

[ Reply to This | # ]
Auotmatically restart the pasteboard server
Authored by: ross_winn on Oct 02, '05 08:52:06AM

I am a user, not a programmer or coder in even the most rudimentary fashion. When you say you made a script, is this an applescript, or some other kind?

Also, did you ever find out why. It happens to me and it is very frustrating.


Ross_Winn @ mac. com
Freelance Geek

[ Reply to This | # ]