微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

bash – 有没有办法从google-chrome的当前标签中获取网址?

我曾经使用python命令在firefox上做到这一点,但最近发生了一些变化,我无法再获取URL了!

>以前用于firefox的内容

#!/bin/bash
current_tab_num () {
    python2 <<< $'import json\nf = open("/home/username/.mozilla/firefox/xxxxx.default/sessionstore.js", "r")\njdata = json.loads(f.read())\nf.close()\nprint str(jdata["windows"][0]["selected"])'
}
current_tab_url () {
    sed -n "$(current_tab_num)p" <(python2 <<< $'import json\nf = open("/home/username/.mozilla/firefox/xxxxx.default/sessionstore.js", "r")\njdata = json.loads(f.read())\nf.close()\nfor win in jdata.get("windows"):\n\tfor tab in win.get("tabs"):\n\t\ti = tab.get("index") - 1\n\t\tprint tab.get("entries")[i].get("url")')
}
current_tab_url

谁能告诉我如何在firefox和/或chrome中执行此操作?

注意:我不懂python,我只是在某处发现了这些命令并在bash中使用它们!

解决方法:

我有同样的问题,并在尝试解决它时通过那里,所以我会在这里发布我的解决方案(这是非常糟糕的).

我使用wmctrl(你可以用xprop代替)和xdotool来做这件事.以前,我使用扩展名使标题栏中的URL可见(然后您可以通过xprop或wmctrl访问该URL).这两种方法都很好用,虽然它并不是真的“干净”.

id=$(wmctrl -l | grep -oP "(?<=)(0x\w+)(?=.*Chromium)") //Put here the regex for the browser you use
xdotool key --window $id "ctrl+l"
xdotool key --window $id "ctrl+c"

您现在在剪贴板中有网址.然后我使用xclip来处理URL.

如果有人找到,我很乐意看到真正的解决方案.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐