Mac 配置Finder当前目录打开iTerm2

[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 就行
  • 优点:Find直接点Go2Shell按钮就可以在当前目录打开终端了

  • 缺点:iTerm2 APPStore 版本每次都是在新的终端窗口中打开,而不是在新的终端标签中打开

更新 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方法-推荐

  • 打开Automator,选择新建,选择服务
  • 服务接受设为没有输入,位置设为Finder
Paste_Image.png
  • 从左侧的资源库中找出 运行AppleScript,拖到右侧,然后保存为Open iTerm Here
Paste_Image.png
  • 在刚刚创建的AppleScript的输入框中输入如下代码


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

  • 为了避免每次都要去点菜单,再去键盘设置里改一下快捷键,然后就可以快速在Finder中通过iTerm打开当前目录了
Paste_Image.png
  • 注意,这个方式在 macOS 10.12 以后,重启系统或者 Finder 后,手动激活 Finder 的这个自定义服务,才能生效
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 【本篇博客为自己查询方便所做,如果您能从中受益,笔者会感到荣幸】 软件和目录结构层面 ~/Library/Appl...
    清水芦苇阅读 3,433评论 3 4
  • 这是我这段时间写的关于Mac Finder的一系列知识和操作技巧,现在整理出来,希望大家能够喜欢。我也将会继续奉献...
    Mac高级玩家阅读 115,935评论 11 236
  • iTerm2介绍 本文初衷 整理自己脑袋中、收藏中的那些资料,来一次清空,让自己重新开始。 帮助 Mac 后来者,...
    UPUPMO阅读 11,097评论 6 88
  • 在手机中 你让我听 屏息凝气 隐约传来 钟声低沉 在风中 抗争、颤抖、淹没 喘息、明灭、消散 只剩下风 苍凉呼啸
    Anand02阅读 141评论 0 1
  • 烟柳红霞何顾,醉梦繁世沉浮。 十年纤柔心墓,倩影婆娑轻抚。 许卿一生共度,月下杯酒莹烛。 往日时光倾覆,风尘伴君莫舞。
    明月笑忘书阅读 116评论 0 0