How can I unlock my computer and display the screen through applescript?

Every morning, I run a “wake up” script that opens a YouTube playlist. However, it does not appear on the screen because my computer automatically locks up after a few minutes of inactivity.

I am using the following script that I received from another question

tell application "System Events"
  tell security preferences
    set require password to wake to false
  end tell
end tell

tell application "ScreenSaverEngine" to quit

But in fact, my computer screen does not turn on. I have to press / move the mouse. And this actually made my computer unusable, only the application of the very first application worked, I had to restart. Maybe it did not unlock?

+3
source share
4 answers

I tested this on 10.10.2 and unlocked the screen.

, , MouseTools. , MouseTools , . MouseTools. System Events . MouseTools , script.

, 1 , . .

-- input your values in these variables
set pword to "my password"
set mousetools to (path to home folder as text) & "path:to:MouseTools"

-- get the current mouse location and add a pixel to each coordinate
set currentLocation to paragraphs of (do shell script quoted form of POSIX path of mousetools & " -location")
set newX to ((item 1 of currentLocation) as number) + 1
set newY to ((item 2 of currentLocation) as number) - 1

-- move the mouse
do shell script quoted form of POSIX path of mousetools & " -x " & (newX as text) & " -y " & (newY as text)

delay 1

-- keystroke your password
tell application "System Events"
    keystroke pword
    delay 1
    keystroke return
end tell
+3

10.10,

  /usr/bin/caffeinate 

:

man -s8 caffeinate

, caffeinate script, script, -, , .

/usr/bin, , , ​​ Apple Dev-Tools.

which caffeinate

, .

, - pmset sleep, , , pmset noidle, . ( , , $! , .)

+2

macOS Sierra (10.12).

do shell script "caffeinate -u -t 3"
tell application "System Events"
    keystroke "<password>"
    delay 1
    keystroke return
end tell

:

+1
source

Tried and tested on OS X El Capitan -------------------------

tell application "System Events"

  if name of every process contains "ScreenSaverEngine" then

    tell application "ScreenSaverEngine"

         quit
end tell

set pword to "password here"

delay 1

tell application "System Events"

    keystroke pword

    delay 1

    keystroke return
end tell

          end if
     end tell
end run
0
source

All Articles