纸帆|ZevenFang

我们终其一生寻找的无非是那个甘愿为你停下脚步,为你驻足的人。

0%

Finder 在当前目录打开 iTerm2

使用 Automator 编写脚本即可实现使用快捷键在当前目录开启终端:

  1. 打开Automator,选择新建,选择服务
  2. 服务接受设为没有输入,位置设为Finder
    20170421
  3. 从左侧的资源库中找出 运行AppleScript,拖到右侧,然后保存为Open iTerm Here
    20170421
  4. 在刚刚创建的AppleScript的输入框中输入如下代码
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    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
  5. 然后通知iTerm的第一个窗口新建标签并跳到这个目录去
  6. 最后再去键盘设置里改一下快捷键,然后就可以快速在Finder中通过iTerm打开当前目录了
    0170421