【问题标题】:Applescript to Launch Chrome (with specifics)启动 Chrome 的 Applescript(具体说明)
【发布时间】:2013-06-06 17:29:36
【问题描述】:

我真的在努力创建一些在 osx 上启动浏览器窗口 (chrome) 的方法,其中包含窗口大小、没有选项卡等细节。传统上,我通过带有 IE 的窗口使用 vb 脚本,这是一个非常简单的练习但我会第一个承认,当谈到 mac 时,我很挣扎。

这是我的愿望清单。

我需要能够打开一个没有状态栏、没有带有给定 URL 的地址栏和特定窗口大小的窗口(最好是 chrome,但可以是除 safari 之外的任何其他浏览器)。我确实使用 do javaScript 在 safari 中管理了一些东西,并尝试使用执行 javascript 和 'window.open' 对 chrome 进行相同的操作,但这不断失败......

救命!

【问题讨论】:

    标签: macos google-chrome applescript


    【解决方案1】:

    我没有找到在 Chrome 中隐藏工具栏的任何方法,但请尝试以下脚本:

    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
    

    【讨论】:

    • fwiw tell window 1 set bounds to {0, 22, 1440, 900} end tell 将在 macbook air 上将新窗口设置为全屏,因为 1440x900 是设备的屏幕分辨率。
    • 非常详尽的答案!谢谢你。我使用第一个示例 - 简单示例 - 在 chrome 上运行 javascript。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2012-12-13
    • 1970-01-01
    • 1970-01-01
    • 2013-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多