Applescript 从 Safari 获取 URL

发布于 2024-12-01 13:23:48 字数 865 浏览 0 评论 0原文

我正在尝试从 Safari 获取 URL,关闭选项卡并在 Chrome 中打开它( TUAW Post )但我不断收到错误:

error "Safari got an error: Can’t get current tab." number -1728 from current tab

从代码行:

set theURL to URL of current tab of window 1

有什么建议吗?

全部代码:

property theURL : ""

tell application "Safari"

    set t set theURL to URL of current tab of window 1
    close current tab

end tell

tell application "Google Chrome"

    set URL of active tab of window 1 to theURL

    activate

end tell

I'm trying to get the URL from Safari, close the tab and open it in Chrome ( TUAW Post ) But I keep getting the error:

error "Safari got an error: Can’t get current tab." number -1728 from current tab

From the code line:

set theURL to URL of current tab of window 1

Any suggestions?

All the code:

property theURL : ""

tell application "Safari"

    set t set theURL to URL of current tab of window 1
    close current tab

end tell

tell application "Google Chrome"

    set URL of active tab of window 1 to theURL

    activate

end tell

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

み青杉依旧 2024-12-08 13:23:48

它对我有用...

tell application "Safari"
    set theURL to URL of current tab of window 1
end tell

您必须显示更多代码,因为错误是由其他原因引起的。让我问你,你是否在另一个tell 块内有tell application Safari 语句?也许它在告诉谷歌浏览器代码块内?如果是这样,请将其删除。

It works for me...

tell application "Safari"
    set theURL to URL of current tab of window 1
end tell

You have to show more code because the error is caused by something else. Let me ask you this, do you have the tell application Safari statement inside of another tell block? Maybe it's inside the tell google chrome block of code? If so remove it.

宁愿没拥抱 2024-12-08 13:23:48

非常感谢大家!这是最终的代码。

property theURL : ""

tell application "Safari"

    set theURL to URL of current tab of window 1

end tell

tell application "Google Chrome"

    tell window 1
        make new tab with properties {URL:theURL}
    end tell

    activate

end tell

Thanks a lot guys! Here is the final code.

property theURL : ""

tell application "Safari"

    set theURL to URL of current tab of window 1

end tell

tell application "Google Chrome"

    tell window 1
        make new tab with properties {URL:theURL}
    end tell

    activate

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