如何使用 Apple Script 退出多个版本的 Firefox?
How do I quit multiple versions of Firefox with Apple Script?
我有两个版本的 firefox。一个应用程序名称为 "Firefox",另一个名为 "Firefox 2"。
我想告诉 AppleScript 关闭 Firefox 的两个实例。这是我的代码
tell application "Firefox" to quit
tell application "Firefox 2" to quit
这很奇怪,因为我可以将它输入到脚本编辑器中,但是当我按保存时它总是变成这样。
tell application "Firefox" to quit
tell application "Firefox" to quit
如何确保它们都关闭?
将原始 Firefox application bundle 复制并重命名为 Firefox 2 ,下面的 example AppleScript code 让我优雅地退出每次出现的 火狐:
set fx1 to "Firefox"
set fx2 to "Firefox 2"
tell application fx1 to quit
delay 2
tell application fx2 to quit
在下面的屏幕截图中,您可以在 回复 窗格 中看到每次出现 Firefox 返回 --> error number 0
,这是一个优雅的退出!除了 0
之外的任何 错误编号 都表示出了问题。
注意:示例 AppleScript code 就是这样,不包含任何可能适当的错误处理。用户有责任根据需要添加任何 错误处理 。查看 try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay 命令 在适当的事件之间可能是必要的,例如delay 0.5
,适当设置延迟的值。
我有两个版本的 firefox。一个应用程序名称为 "Firefox",另一个名为 "Firefox 2"。
我想告诉 AppleScript 关闭 Firefox 的两个实例。这是我的代码
tell application "Firefox" to quit
tell application "Firefox 2" to quit
这很奇怪,因为我可以将它输入到脚本编辑器中,但是当我按保存时它总是变成这样。
tell application "Firefox" to quit
tell application "Firefox" to quit
如何确保它们都关闭?
将原始 Firefox application bundle 复制并重命名为 Firefox 2 ,下面的 example AppleScript code 让我优雅地退出每次出现的 火狐:
set fx1 to "Firefox"
set fx2 to "Firefox 2"
tell application fx1 to quit
delay 2
tell application fx2 to quit
在下面的屏幕截图中,您可以在 回复 窗格 中看到每次出现 Firefox 返回 --> error number 0
,这是一个优雅的退出!除了 0
之外的任何 错误编号 都表示出了问题。
注意:示例 AppleScript code 就是这样,不包含任何可能适当的错误处理。用户有责任根据需要添加任何 错误处理 。查看 try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay 命令 在适当的事件之间可能是必要的,例如delay 0.5
,适当设置延迟的值。