在Automator中按顺序运行多个Applescripts

问题描述 投票:0回答:1

我正在尝试自动化这个过程。

第1步:将系统日期更改为特定日期。

第2步:打开一个应用程序。

第3步:将系统日期更改回正常状态。

现在在Automator上,我有三个这样的苹果脚本。

enter image description here

on run {input, parameters}

tell application "Terminal"
    do script with command "sudo date 082704002018"
    activate
end tell

delay 1
tell application "System Events"

    keystroke "mypassword" & return
    delay 3

end tell

end run

on run {input, parameters}

tell application "Terminal"
    do script with command "open -a applicationName"
    activate
end tell

end run

on run {input, parameters}

tell application "Terminal"
    do script with command "sudo ntpdate -u time.apple.com"
    activate
end tell

delay 1
tell application "System Events"

    keystroke "mypassword" & return
    delay 3

end tell

end run

问题是Automator只运行第一个代码。我不知道如何让它按顺序运行所有代码。

对不起,如果这是一个愚蠢的问题。我对automator和applescript完全不熟悉。

谢谢

macos applescript automator
1个回答
1
投票

我不太清楚你为什么选择使用三个独立的AppleScripts。您可以将它们全部合并到一个AppleScript中,就像我在下面的示例中所做的那样。我不太清楚你为什么使用“激活”命令。我不认为它们是必要的,所以我删除了那些代码行。无论如何,以下代码应该适合你...

tell application "Terminal"
    do script with command "sudo date 082704002018"
end tell
delay 1
tell application "System Events"
    keystroke "mypassword" & return
    delay 3
end tell
tell application "Terminal"
    do script with command "open -a applicationName"
    delay 1
    do script with command "sudo ntpdate -u time.apple.com"
end tell
delay 1
tell application "System Events"
    keystroke "mypassword" & return
    delay 3
end tell

或者,启动Terminal应用程序以运行shell脚本不是必需的,因为您可以使用“do shell script”命令在AppleScript中运行shell脚本。以下AppleScript代码是您的代码,仅使用八行代码。

do shell script "sudo date 082704002018"
tell application "System Events" to keystroke "mypassword" & return
delay 3
do shell script "open -a applicationName"
delay 1
do shell script "sudo ntpdate -u time.apple.com"
delay 1
tell application "System Events" to keystroke "mypassword" & return

如果我的代码版本抛出错误,可能需要调整延迟命令或重新插入activate命令

如果您非常喜欢使用您的代码版本和三个单独的Applescripts,只需从每个AppleScript中删除on run {input, parameters}end run代码行,这样可以消除您的问题

© www.soinside.com 2019 - 2024. All rights reserved.