Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to write a script that kills XCode, Chrome, and the iOS Simulator, whenever I fast-user-switch on Lion.

How do I trigger such a script? And should I use killall type commands?

share|improve this question

I can't think of any way to have fast user switching trigger running a script. But you could use a script that both quits the apps and switches to another user. If you save it to /usr/bin/, it will be on the path even on a guest account.

#!/bin/bash

cgsession="/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession"

osascript -e 'try' -e 'quit app "Xcode"' -e 'end try' &
osascript -e 'try' -e 'quit app "Google Chrome"' -e 'end try' &

if [[ $# == 0 ]]; then
    "$cgsession" -suspend
else
    userid="$(id -u "$1")"
    [[ -z $userid ]] && exit 1
    "$cgsession" -switchToUserID $userid
fi
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .