有用收藏首页投稿(暂停使用,暂停投稿)

Mac 配置Finder当前目录打开iTerm2

2016-07-11  本文已影响6866人  木猫尾巴

[TOC]

说明

在Finder加上一个打开当前路径的终端的功能有三种实现

FinderGo AppGo2Shell AppAppleScript

FinderGo.app

推荐这个方式,兼容性和适配更好,如果想更快速在当前目录打开 iterm2,建议配合 AppleScript 方式

使用方法源码地址的文档有介绍,支持 iterm2 hyper Terminal 三种方式

Go2Shell.app

使用方法

Paste_Image.png

进入 Preferences 的方式

# 新老版本都可以通过命令行打开
open -a Go2Shell --args config
# v2.3 直接在应用文件中打开 Go2Shell 就行

更新 Go2Shell 经过测试 2.3 版本可以在 MacOS 10.11 使用

image.png

填写内容为

cd %PATH%; clear; echo -e "Last login: `date`"; pwd

使用方法,按图内的设置,点击 Install Go2Shell from Finder

Finder 出现图标

image.png

点击右边这个>_<图标,就可以在 iterm2 中以新窗口的模式打开一个 terminal

删除这个功能,或者图标显示错误很好处理,按住 cmd 键,鼠标拖拽这个图标到外面释放图标,就可以删除这个功能了

配置Automator方法-推荐

Paste_Image.png Paste_Image.png


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的第一个窗口新建标签并跳到这个目录去

Paste_Image.png
上一篇下一篇

猜你喜欢

热点阅读