使用快捷键打开当前目录iTerm

第一步:打开Mac自带程序自动操作,新建快速操作
开始创建服务

参数设置
第二步:点击操作,选择资源库下面的实用工具,点击运行AppleScript拖入到右边
添加服务
第三步:将下面的代码放到AppleScript里面,保存为Open iTerm
on run {input, parameters}
    tell application "Finder"
        set pathList to (quoted form of POSIX path of (folder of the front window as alias))
        set command to "clear; cd " & pathList
    end tell
    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 the first window
            if isRunning and hasNoWindows is false then
                create tab with default profile
            end if
            tell current session to write text command
        end tell
    end tell
end run

代码意思是将当前最前面的Finder地址如果获取不到,则返回桌面地址
然后通知iTerm的第一个窗口新建标签并跳到这个目录去

第四步:打开系统偏好设置-》键盘-》快捷键-》服务

image.png

注意:设置的快捷键不能与Finder自带快捷键冲突。

第五步:重启Finder,打开终端输入:killall Finder
第六步:随意进入一个文件夹,使用快捷键吧~

你可能感兴趣的:(使用快捷键打开当前目录iTerm)