Finder中打开iTerm

作者: ldldlkdldld | 来源:发表于2016-11-03 09:54 被阅读337次

通过Automator可以自意义services,services可以认为是扩展菜单,为应用添加系统未曾提供的功能。本文通过Automator为Finder添加一个扩展菜单,实现当在Finder中选中一个文件夹时,可通过右键菜单直接打开iTerm,并定位到对应目录下。

添加Service

新建一个Automator,类型选择Service。

使用Automator新建Service

添加两个Action,第一个为Get Selected Finder Items,这个是第二个Action的输入参数,当用鼠标选中文件时,通过这个Action可以获得文件夹路径等信息。

第二个Action为Run AppleScript,Action如下图所示:

Finder添加打开iTerm功能

在第二个Action中添加AppleScript,这样当执行service时,便会触发AppleScript执行,AppleScript如下:

-- Adapted from these sources:
-- http://peterdowns.com/posts/open-iterm-finder-service.html
-- https://gist.github.com/cowboy/905546
-- 
-- Modified to work with files as well, cd-ing to their container folder
on run {input, parameters}
  tell application "Finder"
        set my_file to first item of input
        set filetype to (kind of (info for my_file))
        -- Treats OS X applications as files.  To treat them as folders, integrate this SO answer:
        -- http://stackoverflow.com/a/6881524/640517
        if filetype is "Folder" or filetype is "Volume" then
            set dir_path to quoted form of (POSIX path of my_file)
        else
            set dir_path to quoted form of (POSIX path of (container of my_file as string))
        end if
    end tell
    CD_to(dir_path)
end run

on CD_to(theDir)
    tell application "iTerm"
        activate
        set go_dir to "cd " & theDir
        set newWindow to (create window with default profile)
        tell current session of first window
            write text go_dir
        end tell
    end tell
end CD_to

完成上述步骤后,保存Service,命名为:Open iTerm Here

测试Service

打开Finder,随便选中一个文件夹,然后右击,选择services -> Open iTerm Here,一切顺利的话,可正确打开iTerm。

相关文章

  • Finder中打开iTerm

    通过Automator可以自意义services,services可以认为是扩展菜单,为应用添加系统未曾提供的功能...

  • iTerm2使用技巧

    安装iTerm2 iTerm2下载地址 在finder中打开iTerm2 下载Go2Shell 常用快捷键(有些和...

  • iTerm2 使用技巧

    安装 官网下载 使用 Homebrew 命令brew install iTerm2安装 在finder中打开iTe...

  • 快速打开iTerm、Terminal

    iTerm/Terminal快速打开,在Finder任何目录、或选中任何文件快速定位到当前文件夹或者当前文件所在目...

  • Mac笔记

    在Finder中打开unix系统文件夹 在终端输入 重启Finder 在Finder打开定位路径快捷键 输入指定路...

  • Go2Shell安装及使用

    Mac安装Go2Shell 用于实现点击Finder上方勾选的图标直接打开iTerm2等终端。可直接访问当前Fin...

  • Mac 配置Finder当前目录打开iTerm2

    [TOC] 说明 在Finder加上一个打开当前路径的终端的功能有三种实现 FinderGo App, Go2Sh...

  • 在Finder中打开终端

    一、从终端进入Finder终端cd到文件件下,想快速打开finder,可以使用命令 二、从finder快速打开终端...

  • 在Finder中打开终端

    在Mac中,如果要在终端中进入在Finder中打开的目录,常用的方法是在终端中先敲入一个"cd ",然后在Fine...

  • MAC 安装zsh 修改环境变量

    打开iterm 修改这个 ~/.zshrc文件 然后重启iterm

网友评论

  • Juniorchen:安装一个叫go2shell的mac app
  • JackpGao:xtrafinder自带这个功能
    ldldlkdldld:@JackpGao 嗯,但是系统升级以后xtrafinder总是崩溃。

本文标题:Finder中打开iTerm

本文链接:https://www.haomeiwen.com/subject/yspbuttx.html