OS X Automator:自动将文本插入出现的文本提示

OS X Automator: Automatically insert text into appearing text prompt

我已经购买了 Shimo - Mac OS X 的 VPN 客户端 - 到目前为止我对此非常满意。

不过,我使用 VPNBook.com 的服务,可以免费访问他们的一些 VPN 服务器。问题是所有免费帐户的密码每 24 小时左右更改一次,用户名保持不变。

Shimo 提供了一个选项,可以为每个 VPN 连接插入用户名,因此唯一需要输入的就是密码。

我有一个 returns 读取和 returns 当前密码的可执行函数。所以,如果我 运行 vpnpw 进入终端,它会打印当前的工作密码。

整个事情看起来像这样:

我现在的计划是实现一个脚本,当 Shimo 要求输入密码时,它会自动调用 vpnpw 并将其插入到提示符中。 Shimo 提供触发器,例如 运行ning 一个 shell 脚本或试图建立连接时的一个应用程序。所以这应该会让事情变得更容易。

这是提示的截图(抱歉是德语):

最好的方法是什么?我考虑过在显示提示时使用 Automator 运行 vpnpw。但是,我一般没有使用 Applescript 或 Automator 的经验。非常感谢您的帮助,因为我想自动化整个过程。

仅供参考,我附上了返回 VPNBook.com under this link.

当前 VPN 密码的脚本

你应该可以做这样的事情....

on run
    set thePwd to do shell script "vpnpw"
    set the clipboard to thePwd
end run

那么我认为您将不得不求助于 GUI 脚本

tell application "System Events"
    keystroke "v" using command down
end tell

您需要在系统首选项中启用 UI 脚本,然后才能运行。你可以看到 how/where 这样做 here

总而言之,您的整个脚本可能看起来像这样...

on run
    set thePwd to do shell script "vpnpw"
    set the clipboard to thePwd

    tell application "Shimo" to activate -- You'll have to check this code, I don't have Shimo to know if this will work

    do shell script "sleep 1" -- just to allow time for shimo to become the front app before the paste

    tell application "System Events"
        keystroke "v" using command down -- paste the clipboard
    end tell
end run