Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.