我制作了一个非常简单的 AppleScript 来关闭 Safari 中的选项卡。问题是,它有效,但不完全有效。只关闭了几个选项卡。这是代码:
tell application "Safari"
repeat with aWindow in windows
repeat with aTab in tabs of aWindow
if [some condition is encountered] then
aTab close
end if
end repeat
end repeat
end tell
我也试过这个脚本:
tell application "Safari"
repeat with i from 0 to the number of items in windows
set aWindow to item i of windows
repeat with j from 0 to the number of tabs in aWindow
set aTab to item j of tabs of aWindow
if [some condition is encountered] then
aTab close
end if
end repeat
end repeat
end tell
...但它也不起作用(相同的行为)。
我在我的系统(2008 年 1 月的 MacBook Pro)以及 Tiger 下的 Mac Pro G5 上进行了尝试,但脚本在两者上都失败了,尽管 Tiger 上的描述性错误要少得多。
运行脚本几次每次都会关闭几个选项卡,直到没有留下任何选项卡,但在关闭几个选项卡后总是失败并出现相同的错误。在 Leopard 下,我得到一个越界错误。由于我使用的是快速枚举(不使用“从 0 到 Windows 中的项目数重复”),所以我不知道如何获得越界错误...
我的目标是使用 Cocoa Scripting Bridge 从我的 Objective-C Cocoa 应用程序中关闭 Safari 中的选项卡,但 Scripting Bridge 以同样的方式失败。不可删除的选项卡显示NULL
在 Xcode 调试器中,而其他选项卡是有效对象,我可以从中获取值(例如它们的标题)。事实上,我首先尝试了 Scripting Bridge,然后告诉自己为什么不直接在 AppleScript 中尝试,我很惊讶地看到了相同的结果。
我必须有一个明显的遗漏或那里的东西......(对我来说,这似乎是Safari AppleScript支持中的一个错误......:S)我使用重复循环和Obj-C 2.0快速枚举来迭代集合之前为零问题,所以我真的看不出这里有什么问题。
任何人都可以帮忙吗?
提前致谢!