Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

1 Answer

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.