如何解锁我的电脑并通过AppleScript显示屏幕?

时间:2014-02-24 17:49:21

标签: macos applescript

我跑了#34;唤醒"脚本每天早上打开一个youtube播放列表。但它并没有在屏幕上显示,因为我的电脑在闲置几分钟后自动锁定。

我使用以下来自其他问题的脚本

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

tell application "ScreenSaverEngine" to quit

但它实际上并没有让我的电脑屏幕开启。我必须按一个键/移动鼠标。它实际上使我的计算机无法使用,只有最前面的应用程序的菜单工作,不得不重新启动。也许它没有正确解锁?

4 个答案:

答案 0 :(得分:3)

我在10.10.2上对此进行了测试,它解锁了屏幕。

首先,您需要下载我写的名为MouseTools的免费程序。它用你的鼠标做事情,在这种情况下,我们可以使用鼠标工具移动鼠标,解锁屏幕。 Get MouseTools here。然后系统事件可以输入您的密码并完成解锁屏幕。然后,您需要在计算机上输入MouseTools的路径,并输入密码以解锁脚本顶部的计算机。

注意代码获取当前鼠标位置并向上移动并向右移动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

答案 1 :(得分:2)

我没有在10.10上测试过这个,但你可能想看看

  /usr/bin/caffeinate 

要查看手册页:

man -s8 caffeinate

我的想法是你要么使用咖啡因来执行脚本的其余部分,要么在脚本运行时让显示器无法入睡,要么设置超时值,显示器将被拒绝睡眠。超时发生后,此行为将停止。

此实用程序位于我的/ usr / bin中,但它可能已与Apple的Dev-Tools一起安装。

which caffeinate

会告诉您它是否已安装在您的系统上。

如果你没有它,那么你可以使用pmset和sleep进行一些工作,所以你指定一个进程何时被唤醒,并杀死你有的 pmset noidle 进程在后台推出。 (在将进程发送到后台后,发送到后台的最新进程的进程号存储在shell中的 $!中。)

答案 2 :(得分:2)

在macOS Sierra上测试过(10.12)。

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

参考:

答案 3 :(得分:0)

在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