Thursday, March 22, 2012

Activating your MacOS Screensaver from the Command Line (and Processing!)

It's a matter of calling osascript with the -e flag, and giving it a statement to evaluate:

  osascript -e 'tell application id "com.apple.ScreenSaver.Engine" to launch'

It's useful at the moment because I'm messing around with a Touchatag RFID reader (drivers are here, btw), using these libraries for Processing.  What I wanna try out first is attaching an RFID tag to the bottom of my coffee mug.  When I leave my desk to get some more tea, I'll tap the mug on the reader and it'll activate my screensaver, which requires a password to unlock.

BTW, here are the two lines (mind the line-wrap, there) in Processing, to kick-off that applescript and activate the screensaver:

  String[] command = { "/usr/bin/osascript","-e","tell application id \"com.apple.ScreenSaver.Engine\" to launch"};
  exec(command);


Easy enough!  Next up, if I've tapped more than three pint glasses of beer, disable the Send button in my email client.

No comments:

Post a Comment