在Mac OS查找器中打开终端

是否有类似于“在这里打开命令窗口”的Mac OS Windows Powertoy ?我通过谷歌搜索找到了几个插件,但想看看哪些最适合开发人员。

643352 次浏览

此外,您可以使用command-C从查找器中复制一个项目,跳转到终端(例如使用Spotlight或QuickSilver)键入'cd '并简单地使用command-v粘贴

如果你安装了Big Cat Scripts (http://www.ranchero.com/bigcat/),你可以添加自己的上下文菜单(右键单击)项。我不认为它带有一个Open Terminal Here applescript,但我使用这个脚本(我不记得是我自己写的,还是从别人的例子中引用的):


on main(filelist)
tell application "Finder"
try
activate
set frontWin to folder of front window as string
set frontWinPath to (get POSIX path of frontWin)
tell application "Terminal"
activate
do script with command "cd \"" & frontWinPath & "\""
end tell
on error error_message
beep
display dialog error_message buttons ¬
{"OK"} default button 1
end try
end tell
end main

类似的脚本还可以通过右键单击获得文件的完整路径,我发现这更有用。

这样的:

https://github.com/jbtule/cdto#cd-to

这是一个小的应用程序,你可以拖到Finder工具栏中,图标非常合适。它使用Terminal, xterm(在X11下),term。

澄清(感谢@vgm64):如果你已经在终端中,这可以让你在不离开终端的情况下快速切换到最上面的Finder窗口。这样,就可以避免使用鼠标。

我已经添加了以下到我的.bash_profile,这样我可以在终端中随时键入cdff

function ff { osascript -e 'tell application "Finder"'\
-e "if (${1-1} <= (count Finder windows)) then"\
-e "get POSIX path of (target of window ${1-1} as alias)"\
-e 'else' -e 'get POSIX path of (desktop as alias)'\
-e 'end if' -e 'end tell'; };\


function cdff { cd "`ff $@`"; };

这是来自这个macosxhints.com终端提示

这比你要求的要多一点,但我推荐Cocoatech的路径查找器给那些希望查找器有更多果汁的人。它包括一个工具栏按钮,用于打开当前目录的终端窗口,或者在每个Finder窗口的底部有一个带有终端命令行的可伸缩窗格。还有许多我现在生活中不可或缺的功能。非常成熟、稳定的软件。 # EYZ0 < / p >

看看这里的开放式终端。它可能与“在这里打开命令窗口”最相似。我使用了>cdto,这是非常相似的,但似乎在处理空格方面更好一些……但并不完美。

它拥有的非常好的功能是“在应用程序开始时检测键下事件,并使用它们修改脚本的行为”,允许脚本在按住⌘键调用时在最前面的终端窗口中打开一个新选项卡。整洁的技巧。

还要注意PCheese的回答;它可能对重度终端用户更有用!

好吧,我意识到有点晚了…也许在我写这篇文章的时候,这个选择还不存在?

不管怎样,我发现通过Fink安装pos包是最简单的解决方案(在这种情况下是先决条件,也许使用MacPorts的人也有类似的方法?)你会得到两个命令:

  1. posd -给出最前端Finder窗口的当前目录(您可以为其创建一个别名cdf=cd posd)
  2. fdc -将最前面的Finder窗口的当前目录切换到终端pwd。这与“open .”略有不同,后者总是打开一个新的finder窗口。

是的,在写cdf之前你必须切换到终端窗口,但我认为这比在Finder工具栏中单击一个按钮要便宜得多。它也适用于iTerm,你不需要下载一个单独的Finder工具栏按钮来打开一个iTerm窗口。这与PCheese提出的方法相同,但是您不必使.bash_profile变得混乱。

在OSX 10.6上的AppleScript有一个错误。(2终端Windows打开)。 我通过在激活后添加关闭命令来解决这个问题。这将关闭第一个终端窗口

on run
tell application "Finder"
try
activate
set frontWin to folder of front window as string
set frontWinPath to (get POSIX path of frontWin)
tell application "Terminal"
activate
close
do script with command "cd \"" & frontWinPath & "\""
end tell
on error error_message
beep
display dialog error_message buttons ¬
{"OK"} default button 1
end try
end tell
end run
我为finder工具栏创建了一个包含3个应用程序的bundle。 其他两个应用程序做:

  • 打开当前选择的Textmate
  • 用当前文件夹打开GitX

更多信息见这里: # EYZ0 < / p >

vgm64d0k发布了一个非常漂亮和苗条的这里的开放式终端的更新版本。更改由詹姆斯·大卫·洛完成。他在他的网站上发表了新版本。只需下载OpenTerminalHere.zip,解压它,将包移动到你的Library/Scripts文件夹,并将它从那里拖到你的Finder工具栏。

它的特别之处在于它总是打开一个新标签是一个终端。应用程序窗口已经打开。非常有用!我还注意到,应用程序按钮的风格更适合雪豹Finder。app样式比由修订发布的cdto样式要多。

我发现一个不可或缺的替代应用程序是DTerm,它实际上在应用程序中打开了一个迷你终端。另外,它适用于几乎所有的东西- Finder, XCode, PhotoShop等。

如果你像我一样关闭了查找工具栏,这个服务会在每个文件夹的上下文菜单中添加一个项目:http://blog.leenarts.net/2009/09/03/open-service-here/

这还允许您打开在Finder树视图中看到的任何文件夹。

从Mac OS X Lion 10.7开始,终端就以服务的形式包含了这个功能。与大多数服务一样,这些默认情况下是禁用的,因此您需要启用它才能显示在Services菜单中。

系统首选项>键盘>快捷方式>服务

启用# EYZ0。还有文件夹中的新终端选项卡,它将在最前面的终端窗口中创建一个选项卡(如果有的话,它将创建一个新窗口)。这些服务适用于所有应用程序,而不仅仅是Finder,它们对文件夹和文本中选择的绝对路径名进行操作。

您甚至可以为它们分配命令键。

服务出现在每个应用程序菜单的Services子菜单中,并在上下文菜单中(控制-单击或右键单击文件夹或路径名)。

文件夹新终端服务将在Finder中变为活动的当您选择一个文件夹时。您不能简单地打开文件夹并“就地”运行服务。回到父文件夹,选择相关文件夹,然后通过Services菜单或上下文菜单激活服务。

此外,如果你将文件夹(或路径名)拖到终端应用程序图标上,Lion终端将打开一个新的终端窗口,你也可以拖到现有窗口的选项卡栏上创建一个新的选项卡。

最后,如果你将一个文件夹或路径名拖到一个选项卡上(在选项卡栏中),前台进程是shell,它将自动执行一个“cd”命令。(在选项卡中拖拽到终端视图只是单独插入路径名,就像在旧版本的terminal中一样。)

你也可以通过命令行或shell脚本来完成:

open -a Terminal /path/to/folder

这相当于在命令行中将文件夹/路径名拖放到终端应用程序图标上。

与此相关的是,Lion Terminal还有用于查找手册页的新服务:在终端中打开手册页在新的终端窗口中显示所选的手册页主题,在终端中搜索人员页面在所选文本上“恰当地”执行。前者还理解手册页引用(“open(2)”)、手册页命令行参数(“2 open”)和手册页url(“x-man-page://2/open”)。

我主要使用这个函数:

cf() {
cd "$(osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)')"
}

你也可以像下面这样为脚本指定一个快捷方式。

重用一个现有的选项卡或创建一个新窗口(终端):

tell application "Finder" to set p to POSIX path of (insertion location as alias)
tell application "Terminal"
if (exists window 1) and not busy of window 1 then
do script "cd " & quoted form of p in window 1
else
do script "cd " & quoted form of p
end if
activate
end tell

重用一个现有的标签或创建一个新的标签(终端):

tell application "Finder" to set p to POSIX path of (insertion location as alias)
tell application "Terminal"
if not (exists window 1) then reopen
activate
if busy of window 1 then
tell application "System Events" to keystroke "t" using command down
end if
do script "cd " & quoted form of p in window 1
end tell

总是创建一个新标签(iTerm 2):

tell application "Finder" to set p to POSIX path of (insertion location as alias)
tell application "iTerm"
if exists current terminal then
current terminal
else
make new terminal
end if
tell (launch session "Default") of result to write text "cd " & quoted form of p
activate
end tell

与10.7中添加的服务相比,前两个脚本有两个优势:

  • 它们使用标题栏上的文件夹,而不是要求您首先选择一个文件夹。
  • 如果最前面的选项卡不忙,比如运行命令、显示手册页或运行emacs,他们就会重用该选项卡。