首页 文章

终端命令打开新的Safari窗口

提问于
浏览
2

从终端在Firefox中打开一个链接非常简单, firefox command有很多选项可用 . 例如,你可以 firefox -new-window "http://stackoverflow.com" 在新窗口中打开链接 .

我想知道你是否可以在Mac上使用Safari?如果已经打开Safari窗口, open "http://stackoverflow.com" 只会打开一个新标签 .
我知道可以让你在"Open in new tab"和"Open in new window"之间切换的应用程序 . 是否有一个特殊的URL前缀告诉Safari打开一个新窗口?或者只是可以通过Objective-C代码?

2 回答

  • 1

    您可以在.profile中使用osascript代码放置以下函数

    码:

    function Safari {
      # Will open a New Safari window with argument 1.
    
    osascript <<EOD
    tell application "Safari" to make new document with properties {URL:"$1"}
    return
    EOD
    
    }
    

    在终端:

    • cd到您的主目录 .

    • 运行:nano .profile

    如果你已经有一个.profile文件,它将会打开,并且那里会有一些代码 .

    • 在任何其他代码下面输入代码 .

    如果您没有,则会打开一个空白.profile文件 .

    • 在其中输入代码 .

    ------输入代码后----

    按住Ctrl键并按x键 .

    在窗口底部,系统会要求您保存更改 .

    enter image description here

    点击y键即可 .

    现在将要求您使用当前名称.profile保存它

    enter image description here

    只需按Enter键即可保存 .

    跑 :

    . ~/.profile
    

    这将更新环境 .

    现在你可以运行:

    Safari  "http://stackoverflow.com"
    

    注意Safari中的Cap“S” .

  • 7

    这使用了一种不同的方法(osascript vs open)但是我认为你要求的是:

    osascript -e "tell application \"Safari\"
        make new document
        set URL of document 1 to \"http://www.apple.com/\"
        set bounds of window 1 to {500, 500, 800, 800}
    end tell"
    

相关问题