Mac finder中打开当前路径的Iterm2终端 超实用小工具

不知道读者们有没有遇到这样的场景,在mac finder的某个文件夹下面,想直接跳转到iterm2,跳过去的目录就是当前目录。从iterm2打开当前目录的finder很简单,直接"open ."即可,但是反过来就不是那么容易了,本文就是为了解决这个痛点。

先看下效果图:

如图所示进入一个文件夹,然后点击finder工具栏上的图标, 即可跳转到iterm2,pwd看一下目录就是跳转过来的目录。

下面讲解下具体步骤

1, 首先关注本公众号,并回复 finder2iterm,即可获得该脚本。

2, 然后mac上下载安装iterm2,可在官网直接下载,注意下载最新版本。

扫描二维码关注公众号,回复: 11528620 查看本文章

3, 然后在mac上打开app "脚本编辑器" ,点击左下角的 "新建文稿" 将下载到的脚本粘贴进去。

效果如下图所示:

(* 


    Open Terminal Here 
     
    A toolbar script for Mac OS X 10.3/10.4
     
    Written by Brian Schlining
 *)


property debug : false


-- when the toolbar script icon is clicked 
-- 
on run
	tell application "Finder"
		try
			set this_folder to (the target of the front window) as alias
		on error
			set this_folder to startup disk
		end try
		
		my process_item(this_folder)
		
	end tell
end run




-- This handler processes folders dropped onto the toolbar script icon 
-- 
on open these_items
	repeat with i from 1 to the count of these_items
		set this_item to item i of these_items
		my process_item(this_item)
	end repeat
end open




-- this subroutine processes does the actual work 
-- this version can handle this weirdo case: a folder named "te'st"ö te%s`t"


on process_item(this_item)
	
	set thePath to quoted form of POSIX path of this_item
	set theCmd to "cd " & thePath & ";clear;"
	
	tell application "iTerm"
		activate
		-- just open a terminal and cd to thePath
		--set newWindow to (create window with default profile)
		
		set aWindow to current window
		
		if aWindow is equal to missing value then
			set aWindow to (create window with default profile)
		else
			tell aWindow
				set t to (create tab with default profile)
			end tell
		end if
		
		
		tell current session of aWindow
			write text "cd " & thePath & ";clear;"
		end tell
		
	end tell
	
	
end process_item

4, 点击 "文件 | 导出 … ",文件格式选择 "应用程序",导出为:自己取一个名字,此处取得finder2iterm, 位置选择要保存到的位置,然后点击"存储"。

然后同时按住"alt+cmd"将该应用程序拖拽到 finder的toolbar中。

大功告成!

猜你喜欢

转载自blog.csdn.net/cxionc123/article/details/105855006