尝试从 Opera 浏览器获取 URL 时出现 AppleScript 错误

发布于 2025-01-18 08:22:13 字数 880 浏览 2 评论 0原文

我在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨洒年华 2025-01-25 08:22:13

无需使用“系统事件”即可与 Opera(或基于 Safari 和 Chromium 的浏览器)进行交互。

打开“Script Editor.app”:
文件>打开词典>并从词典列表中选择“Opera.app”,您可以浏览它的词典。

基于此,您可以使用以下代码片段获取活动选项卡的 URL:

tell application "Opera"
    return URL of active tab of front window
end tell

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:

tell application "Opera"
    return URL of active tab of front window
end tell
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文