让Shell脚本等到AppleScript完成?

时间:2016-10-24 10:50:26

标签: shell unix applescript

我有一个调用AppleScript的shell脚本。 AppleScript对具有给定文档的软件运行一些自动化测试。

AppleScript完成执行后,我在shell脚本中使用mv命令将文档移动到其他文件夹,然后我移动下一个文档,以便AppleScript可以使用这个新文档运行这些测试。但是一旦调用AppleScript,它就会将文档移动到另一个文件夹,而不会在该文档上运行那些测试。

如何在shell脚本中等待,以便在AppleScript完成所有测试后才移动文档?

1. mv $file "/path/to/file" (Moving the document to the execution folder)
2.  osascript /pathto/applescript.app (it will use this execution folder to run its tests)
3.  mv "/path/to/file" /Users/Desktop/tempfolder (moving the document on which the test is completed to a temp folder)

步骤2和3一个接一个地无需等待,因此在测试完成之前移动要运行测试的文档。

2 个答案:

答案 0 :(得分:0)

通常,shell命令按顺序执行。也就是说,在当前的一个语句执行完毕之前,下一个语句不会运行,无论它是否成功。因此,如果是这种情况,您只需在一个接一个的命令后编写脚本。

我想osascript /pathto/applescript.app在一个不同的进程中运行一些任务,并且osascript从它自己的执行返回,而进程正在执行你想要的"还在运行。

你可以做的是ps -aux | grep applescript.app然后从中获取pid,然后执行一段时间循环以查看程序何时停止。但这似乎过度设计了,你不知道applescript.app的执行名称。

如果我错了,请任何人纠正我

答案 1 :(得分:0)

正如Mayerz所说,shell脚本命令正在等待指令结束转移到下一个AppleScript命令。无论如何,您还可以使用“考虑应用程序响应”块。以下是在Finder中移动的示例:

set A to ("myVolume:Users:Me:Documents:sample.mov") as alias
set B to ("Users:me:Desktop:") as alias
tell application "Finder"
    considering application responses
        move A to B
    end considering
end tell
display dialog "done"

使用do shell脚本的类似示例:

set A to ("myVolume:Users:Me:Documents:sample.mov") as alias
set B to path to desktop
set AU to POSIX path of A
set BU to (POSIX path of B) & "test2.mov"
tell application "Finder"
    considering application responses
        do shell script "mv " & (quoted form of AU) & " " & (quoted form of BU)
    end considering
end tell
display dialog "done"
相关问题