我認為我使用ignoring application responses不正確。
我想要做的是嵌套操作,這些操作不依賴于由它們嵌套在其中的應用程式撰寫的腳本。
在下面的示例中,有一個依賴于application "System Events"andapplication process myApp等的重復回圈。但是無論這個回圈中的任何操作,我都希望它們忽略application "System Events"andapplication 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:").
uj5u.com熱心網友回復:
pPath已經是一個POSIX file,洗掉POSIX file
set newPath to pPath as alias
在這種情況下,使用 HFS 路徑更簡單
set hPath to "myDisk:outputPath"
...
set newPath to alias hPath
uj5u.com熱心網友回復:
這完全取決于誰擁有命令。知道誰擁有該命令,您可以使用嵌套的 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
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/334607.html
