◎软件环境:
◎功能描述:
在Alfred输入框中输入想要执行的命令,可以选择在当前iterm窗口执行,也可以新起一个窗口执行命令。不需要手动切换到iterm窗口后再输入命令执行,提高了效率,当然像reboot、rm、mv、kill,pkill这种容易手误的危险命令还是不要使用执行,风险太大,特别是在当前iterm窗口执行命令的时侯!推荐使用新窗口执行命令的方式。
◎实现思路:
直接使用系统调用iterm的功能,当iterm没有启动时先唤醒iterm,然后再使用iterm在当前窗口或新窗口执行命令。Usage:rc/rn
[command]
tell application "System Events" -- some versions might identify as "iTerm2" instead of "iTerm" set isRunning to (exists (processes where name is "iTerm")) or (exists (processes where name is "iTerm2")) end tell tell application "iTerm" activate set hasNoWindows to ((count of windows) is 0) if isRunning and hasNoWindows then create window with default profile end if select first window tell current session of current window to write text "{query}" end tell set query to "{query}" EOF echo ${query} # 新起窗口执行命令 tell the first window if isRunning and hasNoWindows is false then create tab with default profile end if tell current session to write text "{query}" end tell
◎效果展示:
◎下载地址:https://github.com/anzhihe/Efficient-office/tree/master/iterm-run-command