sli*_*fty 9 google-chrome applescript automator bash-scripting macos
好吧,苏,我有一个有趣的坚果要破解。
我有 8 个屏幕排成一行,全部连接到一个运行 Snow Leopard 的强大 G5(是的,4 个显卡;大约 15,000 像素宽!)。我正在设置一个演示,它使用 8 个全屏 Chrome 浏览器窗口,每个窗口都指向不同的 URL。每次重新启动计算机时手动执行此操作很麻烦。
鉴于此设置,我想编写一个脚本来自动:
我没有使用过 automator,我对 shell 脚本也不是特别熟悉,但我想知道是否有来自人群的任何奇特的建议。
更新:即使我需要将 Automator 用于高级功能,我最终还是希望有一种方法可以从命令行/脚本触发脚本。如果需要,我希望能够从 shell 远程打开这个演示。
我想到了!
Applescript 是一个很好的资源,chrome 有一个字典(你可以在“Applescript 编辑器”中查看它,然后选择“打开字典”并在列表中找到 Chrome)。
编码:
set screenCount to 8
set screenWidth to 1950
set baseURL to "http://localhost:8000"
tell application "Google Chrome"
activate
repeat while window 1 exists
close window 1
end repeat
repeat with x from 1 to screenCount
set w to make new window with properties {bounds:{screenWidth * (x - 1), 500, 500 + screenWidth * (x - 1), 1000}}
tell application "System Events" to keystroke "F" using {command down, shift down}
set URL of active tab of w to (baseURL & "/" & "#" & (x - 1))
end repeat
end tell
Run Code Online (Sandbox Code Playgroud)
该脚本执行以下操作:
请记住,我的 URL 符合特定公式(例如http://localhost:8000/#0),因此很容易动态生成它们。对于具有随机相似需求的任何人,您都可以将此作为起点。
最后,对于终端要求,您可以使用以下行在终端上运行 applescript:
osascript [脚本名称]
归档时间: |
|
查看次数: |
9429 次 |
最近记录: |