Last active
November 21, 2016 00:00
-
-
Save suhajdab/edfa6577255ebc9c6a74 to your computer and use it in GitHub Desktop.
Super simple remote unlock for OSX via NodeJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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