我认为我使用ignoring application responses
不正确。
我想做的是有嵌套的动作,不依赖于由它们嵌套的应用程序编写脚本。
在下面的例子中,有一个依赖于application "System Events"
和application process myApp
等的重复循环。但是无论在这个循环中有什么动作,我希望这些忽略application "System Events"
和application process myApp
等。我该如何做到这一点?
set myApp to "someApp"
set pPath to POSIX file "/Volumes/myDisk/outputPath"
tell application myApp to activate
tell application "System Events"
tell application process myApp
tell window myApp
--some code here
repeat while progress indicator 1 of sheet 1 exists
ignoring application responses
set newPath to POSIX file pPath as alias
set currentDate to current date
end ignoring
end repeat
--some code here
end tell
end tell
end tell
返回的错误:
get POSIX file (file "myDisk:outputPath:") of application process "somApp"
Result:
error "No result was returned from some part of this expression."
在这里,我希望get POSIX file (file "myDisk:outputPath:") of application process "somApp"
只是get POSIX file (file "myDisk:outputPath:")
。
pPath
已经是POSIX file
,删除POSIX file
set newPath to pPath as alias
在这种情况下,使用HFS路径更简单
set hPath to "myDisk:outputPath"
...
set newPath to alias hPath
这完全取决于谁拥有这个命令。知道谁拥有该命令后,您可以使用嵌套的tell语句将其重定向到正确的应用程序(或框架)。例如,这里我试图将(当前日期)命令重定向到安装的脚本添加的框架.
set myApp to "someApp"
set pPath to POSIX file "/Volumes/myDisk/outputPath"
set newPath to pPath as alias
tell application myApp to activate
tell application "System Events" to tell process myApp to tell window 1
--some code here
repeat while progress indicator 1 of sheet 1 exists
tell scripting additions to set currentDate to current date
end repeat
--some code here
end tell
但这并不总是有用。正确稳定的解决方案就是"解耦";嵌套的告知块,并将它们转换成单独的告知块。在您的示例中,我将这样做:
set myApp to "someApp"
set pPath to POSIX file "/Volumes/myDisk/outputPath"
set newPath to pPath as alias
tell application myApp to activate
tell application "System Events" to tell process myApp to tell window 1
--some code here
end tell
set indicatorExists to true
repeat while indicatorExists
tell application "System Events" to tell process myApp to tell window 1
set indicatorExists to progress indicator 1 of sheet 1 exists
end tell
set currentDate to current date -- now this command is not nested
end repeat
tell application "System Events" to tell process myApp to tell window 1
--some code here
end tell