A tiny tutorial for remotely sending your Mac to the login screen
I’ve been meaning to do this for a while and as of last night, I finally got around and did it. What is it you ask? Well, to explain it let me use a little story:
While I work, there are occasions when myself along with a few other co-workers go for walks around Grand Rapids to stretch our legs and to just break the monotonous feel of coding forms in the dark. For the most part, we all set oour computers to the login screen for the simply security thats someone will not be able to jump on our computers and get to our personal files and such.
The problem with me is, every few times we go for walks to go to get some kind of food/drink from the nearby party store I forget to put my computer to the login screen. Now, I know that no one in the office where I work is going to mess with my computer but every now and then I get paranoid.
So! To rid myself of this paranoia, I have written a simple AppleScript that works with a bash shell script all of which is triggered by a rule set in Mail that when it sees an e-mail from my phone with the message “switch” it instantly switches to the login window.
For all of you interested here’s the AppleScript (it’s only use is to call the shell script):
do shell script "[folder path to the script]/gotologin”
With the AppleScript, you have to set the path of where you have the gotologin script. For example, I save mine in
~/Documents/scripts/, so my AppleScript would look like this:
do shell script "~/Documents/scripts/gotologin"
And here’s the bash script (called gotologin):
#!/bin/sh
# Fast User Switching from the command line
CGSession='/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession'
# display login screen
exec "$CGSession" -suspend
exit
;;
esac
Simple enough.
Now, to set up a rule in Mail is easy as pie.
I’m assuming you have an e-mail account set up in Mail already (if not, click here or see the Mail help) and with that said here’s your simple how-to as to setting up a rule in Mail.
First, go to your Mail preferences and click Rules. Next, click Add Rule and a window will pop up. Within the window, you can add a description and set up your rule parameters. What I did was added one rule that said From - Is equal to - “[my phones e-mail address]“, then added another rule that said Message Content - Contains - “switch”. Then, on the final line, I chose Run AppleScript then I chose the location of the AppleScript, then clicked OK.
And it’s all done!
Mind you, you should definitely save your AppleScript and bash script somewhere where they won’t be moved because if they are moved, then rule won’t function correctly in Mail…