如何使用 AppleScript 登录远程 Mac?

问题描述

我需要实现的是,使用 AppleScript:

  1. 唤醒远程 iMac
  2. 输入密码
  3. 接受密码登录

到目前为止,我成功做的是启用远程事件并连接到 iMac,但现在我卡住了。这是我到目前为止尝试过的:

set remotemachine to "eppc://192.168.0.26"

tell application "System Events" of machine remotemachine
    keystroke 123
end tell

然而,这让我无处可去。它对我说“错误:应用程序未启动。编号 -600”。抱歉,这不是确切的英文字符串。

有谁知道我做错了什么? ?

提前致谢。

解决方法

两个主要问题:

  1. System Events 不会在远程机器上永久运行,您无法从本地机器启动应用程序。您必须使用 System Events 启动 Finder,这是唯一永久运行的应用程序。

  2. 您必须明确解决远程机器的 FinderSystem Events,但还要添加一个 using terms from 块,因为必须在本地解析术语。

此示例在远程计算机上启动 System Events 并重新调整桌面文件夹的路径

set RemoteMachine to "eppc://192.168.0.26"

tell application "Finder" of machine RemoteMachine
    using terms from application "Finder"
        if "System Events" is not in (get name of processes) then
            open application file id "com.apple.systemevents"
            repeat until "System Events" is in (get name of every process)
                delay 1
            end repeat
        end if
    end using terms from
end tell

tell application "System Events" of machine RemoteMachine
    using terms from application "System Events"
        set x to path of desktop folder
    end using terms from
end tell

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...