… of many things …

… of many things … header image 2

Fast User Switching via Keyboard

June 22nd, 2008 · No Comments

I copied the following Bash script from MacScripter and combined it with TextExpander's ability to execute Apple Script in order to give me the ability to switch to the Login screen via a keyboard shortcut (I mapped it to 'ffus').

BASH:
  1. #!/bin/sh
  2. # Fast User Switching from the command line
  3. # I saved mine as /usr/local/bin/fus
  4.  
  5. CGSession='/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession'
  6.  
  7. case "$#" in
  8. 0)
  9. # display login screen
  10. exec "$CGSession" -suspend
  11. exit
  12. ;;
  13. esac
  14.  
  15. # No reason to display the login panel for the current user
  16. case "$1" in
  17. "$USER" | "$UID")
  18. exit 0
  19. ;;
  20. esac
  21.  
  22. # can pass in a (short) username or userid
  23. id=`/usr/bin/id -u "$1"` || exit
  24.  
  25. # display login panel for user
  26. exec "$CGSession" -switchToUserID "$id"

The Apple Script I use to invoke this from TextExpander is:

APPLESCRIPT:
  1. do shell script "/usr/local/bin/fus "

Tags: Mac

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment