gpt4 book ai didi

macos - 使用 AppleScript 关闭 FireFox 中的特定选项卡

转载 作者:行者123 更新时间:2023-12-02 22:30:24 25 4
gpt4 key购买 nike

我需要编写脚本来关闭 FireFox 中具有特定标题的选项卡。是否有与下面的 AppleScript 示例等效的 FireFox?

在 Safari 中关闭标签页:

tell application "Safari"
delete (every tab of every window where its name contains "[done]")
end tell

在 Chrome 中关闭标签页:

tell application "Google Chrome"
delete (every tab of every window where its title contains "[done]")
end tell

最佳答案

由于 Firefox 不支持任何 AppleScript,您需要依赖 UI 脚本。当然,Firefox 的非标准 UI 也无济于事,但仍有可能。试试这个:

tell application "System Events" to tell process "firefox"
set frontmost to true
repeat with w from 1 to count of windows
perform action "AXRaise" of window w
set startTab to name of window 1
repeat
if name of window 1 contains "[done]" then
keystroke "w" using command down
else
keystroke "}" using command down
end if
delay 0.2
if name of window 1 is startTab then exit repeat
end repeat
end repeat
end tell

关于macos - 使用 AppleScript 关闭 FireFox 中的特定选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12358270/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com