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

本文介绍了一种在Mac系统中实现Finder与iTerm2之间快速切换的方法,通过使用特定脚本,用户可以在Finder中直接打开iTerm2并定位到当前目录,大大提升了工作效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

 

先看下效果图:

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

 

下面讲解下具体步骤

 

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

 

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

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中。

 

 

大功告成!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值