按以下步骤操作即可,不需要保存,代码立即生效。
将以下代码放到上图所示中:
on alfred_script(q)
if application "iTerm2" is running or application "iTerm" is running then
run script "
on run {q}
tell application \"iTerm\"
activate
try
select first window
set onlywindow to true
on error
create window with default profile
select first window
set onlywindow to true
end try
tell the first window
create tab with default profile
tell current session to write text q
end tell
end tell
end run
" with parameters {q}
else
run script "
on run {q}
tell application \"iTerm\"
activate
try
select first window
on error
create window with default profile
select first window
end try
tell the first window
tell current session to write text q
end tell
end tell
end run
" with parameters {q}
end if
tell application \"iTerm\"
end alfred_script
这篇博客介绍了如何通过AppleScript自动化在iTerm(或iTerm2)中创建窗口、选择会话并执行指定的代码,无论iTerm是否正在运行。此方法对于开发者快速运行命令行脚本非常有用。
3798

被折叠的 条评论
为什么被折叠?



