【发布时间】:2016-09-07 21:49:53
【问题描述】:
我想知道如何启动一个全新的 Chrome 实例(请参阅下面的脚本),它将被带到前面。目前,shell 脚本在后台打开新的 Chrome 实例,这不是最佳的。从 Applescript 执行 shell 脚本并不能解决这个问题。
有趣的是,如果我直接从 AppleScript 使用 shell 命令打开 Chrome,它似乎会在前台打开:
set q to "'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' --user-data-dir=/tmp/1234"
do shell script q
Applescript
do shell script "~/bin/chrome-fresh"
Shell 脚本
#!/bin/sh
# This is quite useful for front-enders, as it will launch a fresh
# Chrome instance with no loaded plugins or extensions that messes
# with your performance profiling or network debugging
#
# Install:
# install -m 555 ~/Downloads/chrome-fresh /usr/local/bin/
CHROME="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
ARGS="$@"
# make a fresh user directory
TMP_USERDIR=$(mktemp -d);
# avoid the dialog on the first startup
touch "$TMP_USERDIR/First Run";
# start chrome using a fresh user directory
"$CHROME" --user-data-dir="$TMP_USERDIR" "$ARGS"
【问题讨论】:
-
在 Applescript 中,“告诉应用程序“xxx”激活”命令将该应用程序置于前面。
-
我知道,但是有几个 Chrome 实例。最后一个怎么控制? PID?
-
tell the last window of application "XXX" to activate- 这不起作用,但应该让你开始。我会检查它并让它工作,但我现在在 Windows 上。
标签: macos shell google-chrome applescript