Skip to content

Instantly share code, notes, and snippets.

@suhajdab
Last active November 21, 2016 00:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save suhajdab/edfa6577255ebc9c6a74 to your computer and use it in GitHub Desktop.
Save suhajdab/edfa6577255ebc9c6a74 to your computer and use it in GitHub Desktop.
Super simple remote unlock for OSX via NodeJS
var applescript = require('applescript');
var http = require('http');
var script =
'tell application "System Events"\n\
if name of every process contains "ScreenSaverEngine" then \n\
tell application "ScreenSaverEngine"\n\
quit\n\
end tell\n\
delay 0.2\n\
else \n\
tell application "Terminal"\n\
do shell script "caffeinate -u -t 1"\n\
end tell\n\
delay 0.5\n\
end if\n\
keystroke "YOUR PASSWORD"\n\
keystroke return\n\
get computer name of (system info)\n\
end tell';
function onRequest ( req, res ) {
applescript.execString( script, function( err, rtn ) {
if ( err ) {
console.error( err );
}
res.writeHead( 200, { 'Content-Type': 'text/plain' });
res.write( err ? 'something went wrong while unlocking' : 'unlocked ' + rtn );
res.end();
});
}
http.createServer( onRequest ).listen( 9091 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment