3

I run a "wakeup" script every morning that opens a youtube playlist. However it doesn't show on screen because my computer auto locks after a few minutes of idle time.

I'm using the following script that I got 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 it doesn't actually make my computer screen turn on. I have to press a key/move the mouse. And it actually made my computer unusable, only the menu of the frontmost application worked, had to restart. Maybe it didn't properly unlock?

fent
  • 17,861
  • 15
  • 87
  • 91
  • Which version of OS X are running? In 10.9+ it's difficult at best, and some type work-around or hack might be required. – l'L'l Feb 24 '14 at 22:32
  • You could try `set require password to wake of security preferences to false` and/or `do shell script "killall ScreenSaverEngine"` (btw - I haven't tested these). – l'L'l Feb 24 '14 at 22:43
  • setting requiring a password to `false` did seem to work. but my computer still felt locked even though I could see the applications. – fent Feb 24 '14 at 23:33
  • yes, i believe that is one of the problems — as you can seemingly unlock the screensaver without a password, but the system remains locked. – l'L'l Feb 26 '14 at 13:44

4 Answers4

3

I tested this on 10.10.2 and it unlocks the screen.

First you'll need to download a free program I wrote called MouseTools. It does things with your mouse and in this case we can use MouseTools to move your mouse which will unlock the screen. Get MouseTools here. And then System Events can enter your password and finish unlocking the screen. Then you'll need to enter the path to MouseTools on your computer and the password to unlock your computer at the top of the script.

Note the code gets the current mouse location and moves it up and right 1 pixel to unlock the screen. Good luck.

-- 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
regulus6633
  • 18,848
  • 5
  • 41
  • 49
  • It's not unlocking the computer for me :/. Running on 10.10.2 as well. It does successfully move the mouse, so I know that part's working, even when the screen is locked, after I press a key to unlock it, my mouse is in a different area (I changed the amount of pixels to move to test). But it's not unlocking. The screen doesn't light up either from having the mouse moved. – fent Feb 11 '15 at 03:44
  • I tested it with the screensaver running and it stopped the screensaver and unlocked the screen. Anyway, that's my best idea so maybe you can make it work for you by using a screensaver instead of the way it's currently locking the screen. – regulus6633 Feb 11 '15 at 16:50
  • Oh, that must be it. I'm not using a screensaver, I'm putting the display to sleep. – fent Feb 12 '15 at 06:59
2

I have not tested this on 10.10, but you may wish to check out

  /usr/bin/caffeinate 

To see the manual page:

man -s8 caffeinate

My idea is that you either use caffeinate to execute the rest of your script, and keeps the display from falling asleep while your script is running, or you set a timeout value, for which the display is denied sleep. This behaviour stops after the timeout has occured.

This utility is in my /usr/bin, but it may have been installed with Apple's Dev-Tools.

which caffeinate

Will tell you if it is installed on your system.

If you don't have it, then you may be able to make something work with pmset and sleep, so you specify when a process is to wakeup, and kill the pmset noidle process you have launched in the background. (Process number of latest process sent to background is stored in $! in the shell after you have sent the process to background.)

McUsr
  • 1,400
  • 13
  • 10
  • ++ for what sounds like the right approach; `caffeinate` does come with a pristine OS 10.10 (and 10.11) installation; on a side note: the `man` option that allows you to specify a _list_ of sections is `-S`, not `-s` - though, curiously, the latter seems to work too; with a single section, you can just specify the section number directly (`man 8 caffeinate`), or just omit the section number altogether (`man caffeinate`) if there's no ambiguity (which is the case here). – mklement0 Oct 30 '15 at 03:04
2

Tested this on macOS Sierra(10.12).

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

Reference:

Community
  • 1
  • 1
jqgsninimo
  • 6,562
  • 1
  • 36
  • 30
0

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
Gonzalo.-
  • 12,512
  • 5
  • 50
  • 82
Paul Hesketh
  • 95
  • 2
  • 10