applescript - 苹果脚本。Firefox 中的窗口名称
问题描述
我想知道 Firefox 中的窗口和选项卡的鬃毛。与其他浏览器配合良好的东西在这里会出现问题。例如:
tell application "Firefox" to get the name of every window
在 Firefox 浏览器中,我有一个带有 apple.com 的窗口和另一个带有 google.com 的窗口,但是脚本给了我这个奇怪的结果:
{"Google", "Apple", "", "", "Amazon.com: Online Shopping for Electronics, Apparel, Computers, Books, DVDs & more", "https://www.mozilla.org/en-US/firefox/new/?redirect_source=firefox-com", "", "", ""}
Amazon 和 mozilla 名称是我确信已关闭的以前的窗口。它还显示了几个“”,我不知道它们来自哪里。
如果我转到文档并单击 Firefox,它说我打开了两个窗口:
Apple
Google
所以,我不明白脚本的结果。为什么它给了我更多信息。
如何获取在 Firefox 中打开的窗口的名称(包括选项卡,如果可能)
解决方案
这是获取所有 Firefox 选项卡名称的解决方法。它不漂亮:)
tell application "Firefox"
activate
tell application "System Events" to keystroke "1" using command down
set firstTitle to name of front window
set tabList to {}
set myTitle to "__f_o_o_b_a_r__" -- some random initial name
set counter to 0 -- make sure that loop ends
repeat until (counter > 100 or myTitle is equal to firstTitle)
tell application "System Events" to key code 121 using control down
delay 0.05
set myTitle to (name of front window)
copy myTitle to the end of the |tabList|
set counter to counter + 1
end repeat
end tell
tabList
在使用全局快捷方式搜索选项卡时,我使用了类似的方法。
推荐阅读
- reactjs - 无法从 api 加载帖子
- blueprism - Blue Prism 流程在通过 Process Studio 运行时使用哪个端口?
- pine-script - 如何根据 pinescript 中的条件找到关闭?
- javascript - 使用 Javascript 将对象添加到现有对象
- javascript - 卡塔:走十分钟
- javascript - 垂直滚动条未显示在用 javascript 填充的 html 表中
- cmake - Qt5 - MinGW64 - qResourceFeatureZlib() 入口点未找到
- docker - 有没有办法在 Kubernetes 集群上创建相互依赖的 pod?
- javascript - 如何从文件名 (PNG) 在 HTML 上制作日期
- sql - DB2 无法从内部查询中选择不同的列值