Dan*_*ola 7 applescript automator macos
我正在尝试分配一个全局键盘快捷键,该快捷键将使用特定的配置文件启动一个新的 iTerm 窗口。(我设法这样做以使用 Automator 和 AppleScript 启动一个新的 Chrome 窗口,但事实证明这更困难)
这相当于激活 iTerm,在顶部菜单中选择 Profiles -> "my profile",按下 "alt" 或 "option",因此它将在新窗口中打开,而不是当前窗口中的新选项卡.
任何想法如何使用 Automator 或 AppleScript 做到这一点?
如果相关,我有 Mac OS Mountain Lion
(对不起,如果这是一个绝对的菜鸟问题,我刚刚从 Windows 转移到 Mac,并且我正在尝试优化我一直在做的事情)
谢谢!
之前的答案不再适用于最新版本的 iTerm2 (3),因为terminal
已经停产。新的方法是使用create window with profile
.
然而,这并没有按预期工作:如果 iTerm 正在运行,它将使用适当的配置文件打开新窗口。但如果 iTerm 未运行,它将使用默认配置文件打开一个窗口,然后使用提供的其他配置文件打开第二个窗口。我想出了以下脚本来解决这个问题:
-- this script will start/activate iTerm (close the default window if the app had been newly started), then open a new session with a desired profile
on is_running(appName)
tell application "System Events" to (name of processes) contains appName
end is_running
set iTermRunning to is_running("iTerm2")
tell application "iTerm"
activate
if not (iTermRunning) then
delay 0.5
close the current window
end if
create window with profile "xxxxxx"
end tell
Run Code Online (Sandbox Code Playgroud)
当然,如果 iTerm 支持命令行参数,那就很容易了。希望它会在某个时候。
归档时间: |
|
查看次数: |
9280 次 |
最近记录: |