Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 如何解锁计算机并通过applescript显示屏幕?_Macos_Applescript - Fatal编程技术网

Macos 如何解锁计算机并通过applescript显示屏幕?

Macos 如何解锁计算机并通过applescript显示屏幕?,macos,applescript,Macos,Applescript,我每天早上运行一个“唤醒”脚本,打开youtube播放列表。然而,它并没有显示在屏幕上,因为我的电脑在空闲几分钟后自动锁定 我使用的是从另一个问题中得到的以下脚本 tell application "System Events" tell security preferences set require password to wake to false end tell end tell tell application "ScreenSaverEngine" to quit

我每天早上运行一个“唤醒”脚本,打开youtube播放列表。然而,它并没有显示在屏幕上,因为我的电脑在空闲几分钟后自动锁定

我使用的是从另一个问题中得到的以下脚本

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

tell application "ScreenSaverEngine" to quit

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

我在10.10.2上测试了它,它解锁了屏幕

首先,你需要下载一个我写的名为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

我还没有在10.10上测试过这个,但您可能希望签出

  /usr/bin/caffeinate 
要查看手册页面,请执行以下操作:

man -s8 caffeinate
我的想法是,要么使用caffeinate来执行脚本的其余部分,并在脚本运行时防止显示器进入睡眠状态,要么设置一个超时值,拒绝显示器进入睡眠状态。此行为在超时发生后停止

此实用程序位于my/usr/bin中,但可能是与Apple的开发工具一起安装的

which caffeinate
将告诉您是否已在您的系统上安装


如果没有,则可以使用pmset和sleep使某些功能正常工作,因此可以指定进程何时唤醒,并终止在后台启动的pmset noidle进程。(将进程发送到后台后,最新发送到后台的进程编号存储在shell中的$!

在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

在macOS Sierra上进行了测试(10.12)

do shell脚本“caffeinate-u-t3”
告诉应用程序“系统事件”
击键“”
延迟1
击键返回
结束语

参考:


正在运行哪个版本的OS X?在10.9+版本中,这是最困难的,可能需要一些类型的变通或破解。您可以尝试
将require password设置为false
和/或
执行shell脚本“killall ScreenSaverEngine”
(顺便说一句,我还没有测试过这些)。将密码设置为
false
似乎确实有效。但我的电脑仍然感觉被锁定,即使我可以看到应用程序。是的,我认为这是问题之一-因为你似乎可以在没有密码的情况下解锁屏幕保护程序,但系统仍然处于锁定状态。它不会为我解锁电脑:/。同样在10.10.2上运行。它确实成功地移动了鼠标,因此我知道该部件正在工作,即使屏幕被锁定,在我按下一个键解锁它之后,我的鼠标位于不同的区域(我更改了移动到测试的像素数量)。但它并没有解锁。移动鼠标时屏幕也不会亮起。我在屏幕保护程序运行时测试了它,它停止了屏幕保护程序并解锁了屏幕。无论如何,这是我最好的主意,所以也许你可以使用屏幕保护程序,而不是它目前锁定屏幕的方式,让它为你工作。哦,一定是这样。我不是在使用屏幕保护程序,我是在让显示器进入睡眠状态
caffeinate
确实配备了原始的OS 10.10(和10.11)安装;另一方面:允许您指定章节列表的
man
选项是
-S
,而不是
-S
——奇怪的是,后者似乎也起作用;对于单个节,您可以直接指定节号(
man 8 caffeinate
),或者在没有歧义的情况下(这里就是这种情况)完全忽略节号(
man caffeinate
)。
do shell script "caffeinate -u -t 3"
tell application "System Events"
    keystroke "<password>"
    delay 1
    keystroke return
end tell