Applescript to Launch Chrome (with specifics)

南楼画角 提交于 2019-12-09 04:18:17

问题


I'm really struggling with creating some method of launching a browser window (chrome) on osx with specifics such as window size, no tabs etc. Traditionally I've used vb script through windows with IE which is a pretty simple exercise but I'll be the first to admit, when it comes to macs I struggle greatly.

So here is my wish list.

I need to be able to open a window (ideally in chrome, but any other browser except safari), that has no status bar, no address bar with a given URL, and a specific window size. I did manage something in safari using do javaScript, and attempted the same with chrome using execute javascript and 'window.open' but this failed continually...

Help!


回答1:


I didn't find any way to hide the toolbar in Chrome, but try something like these scripts:

tell application "Google Chrome"
    open location "http://example.com"
    tell window 1 to enter presentation mode
end tell
tell application "Google Chrome"
    tell (make new window)
        set URL of active tab to "http://example.com"
        set bounds to {0, 22, 1200, 900}
    end tell
    activate
end tell
tell application "Safari"
    make new document with properties {URL:"http://example.com"}
    tell window 1
        set bounds to {0, 22, 1200, 900}
    end tell
    activate
end tell
tell application "System Events" to tell process "Safari"
    tell menu "View" of menu bar 1
        if exists menu item "Hide Toolbar" then click menu item "Hide Toolbar"
        if exists menu item "Hide Status Bar" then click menu item "Hide Status Bar"
        if exists menu item "Hide Tab Bar" then click menu item "Hide Tab Bar"
        if exists menu item "Hide Bookmarks Bar" then click menu item "Hide Bookmarks Bar"
    end tell
end tell


来源:https://stackoverflow.com/questions/16948093/applescript-to-launch-chrome-with-specifics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!