尝试从 Opera 浏览器获取 URL 时出现 AppleScript 错误
我在Opera浏览器中打开了一个页面,我正在尝试从终端获取其URL。
我已经设法这样做了:
osascript -e 'tell application "System Events" to return value of text field "Address field" of first group of text field "Address bar" of toolbar "Navigation" of group "Browser contents" of second group of first group of front window of application process "Opera"'
它有效,但是它需要访问系统事件和可访问性许可集。我想直接访问Opera,例如 for Google Chrome 。 因此,我试图像这样重写它:
osascript -e 'tell application "Opera" to return value of text field "Address field" of first group of text field "Address bar" of toolbar "Navigation" of group "Browser contents" of second group of first group of front window'
但是有一个错误:
49:56: syntax error: A “"” can’t go after this identifier. (-2740)
有什么想法解决它?
I have a page opened in Opera browser and I'm trying to get its URL from terminal.
I've managed to do it like this:
osascript -e 'tell application "System Events" to return value of text field "Address field" of first group of text field "Address bar" of toolbar "Navigation" of group "Browser contents" of second group of first group of front window of application process "Opera"'
It works, but it requires access to System Events and Accessibility permission set. I'd like to access Opera directly like in this solution for Google Chrome.
So I've tried to rewrite it like this:
osascript -e 'tell application "Opera" to return value of text field "Address field" of first group of text field "Address bar" of toolbar "Navigation" of group "Browser contents" of second group of first group of front window'
But got an error:
49:56: syntax error: A “"” can’t go after this identifier. (-2740)
Any ideas how to fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无需使用“系统事件”即可与 Opera(或基于 Safari 和 Chromium 的浏览器)进行交互。
打开“Script Editor.app”:
文件>打开词典>并从词典列表中选择“Opera.app”,您可以浏览它的词典。
基于此,您可以使用以下代码片段获取活动选项卡的 URL:
It is possible to interact with Opera (or Safari and Chromium based browsers) without using of "System Events".
With opening the "Script Editor.app":
File > Open Dictionary > and choosing "Opera.app" from the list of dictionaries you can browse it's dictionary.
Based on this with the following snippet you can fetch the URL of the active tab: