通过命令行在macOS上打开URL

发布于 2025-01-26 23:31:29 字数 36 浏览 3 评论 0原文

如何通过命令行上的MacOS在MacOS上打开一个URL?

How can I open a URL on macOS via the command line?

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

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

发布评论

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

评论(3

铁憨憨 2025-02-02 23:31:29

我找到了通过命令行1在MACOS上打开URL的两种方法

open https://google.com
on run argv
    tell application "Safari"
        open location item 1 of argv
        activate
    end tell
end run
osascript open-safari.applescript https://google.com

I have found two ways to open a URL on macOS via command line

1.

open https://google.com
on run argv
    tell application "Safari"
        open location item 1 of argv
        activate
    end tell
end run
osascript open-safari.applescript https://google.com
浸婚纱 2025-02-02 23:31:29
open location <theUrl>

通过AppleScript知道,可以直接打开URL。默认浏览器将被触发。无需明确调用Safari。

open location <theUrl>

Is Known by AppleScript and can open the url directly. The default browser will be triggered. No need to invoke Safari explicitly.

凹づ凸ル 2025-02-02 23:31:29

该苹果公司将仅启动Safari ,即使不是默认的浏览器,也将使用所需的URL将其带到前景。

on run argv
    launch application "Safari"
    delay 1
    tell application "Safari"
        open location item 1 of argv
    end tell
    activate application "Safari"
end run

这样通过osascript运行它:

osascript safari-open-url.scpt https://someurl.com

This AppleScript will launch Safari only and bring it to the foreground with the desired URL even when it is not the default browser.

on run argv
    launch application "Safari"
    delay 1
    tell application "Safari"
        open location item 1 of argv
    end tell
    activate application "Safari"
end run

Run it via osascript like this:

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