AppleScript - 如何让动作忽略它们嵌套在其中的 tell 语句?
AppleScript - how to have actions ignore the tell statements they are nested within?
我认为我使用 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
但这并不总是有帮助。 正确且稳定的解决方案 是“解耦”嵌套的 tell 块并将它们转换为单独的 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
我认为我使用 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
但这并不总是有帮助。 正确且稳定的解决方案 是“解耦”嵌套的 tell 块并将它们转换为单独的 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