macos 在 Mac OS finder 中打开终端

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/420456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 06:00:17  来源:igfitidea点击:

Open terminal here in Mac OS finder

macosterminalfinder

提问by Abdullah Jibaly

Is there something similar to the "Open Command Window Here" Windows Powertoy for Mac OS? I've found a couple plugins through a google search but wanted to see what works best for developers out there.

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

回答by Chris Page

As of Mac OS X Lion 10.7, Terminal includes exactly this functionality as a Service. As with most Services, these are disabled by default, so you'll need to enable this to make it appear in the Services menu.

从 Mac OS X Lion 10.7 开始,终端将这一功能作为服务包含在内。与大多数服务一样,默认情况下这些服务是禁用的,因此您需要启用它以使其出现在“服务”菜单中。

System Preferences > Keyboard > Shortcuts > Services

系统偏好设置 > 键盘 > 快捷方式 > 服务

Enable New Terminal at Folder. There's also New Terminal Tab at Folder, which will create a tab in the frontmost Terminal window (if any, else it will create a new window). These Services work in all applications, not just Finder, and they operate on folders as well as absolute pathnames selected in text.

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

You can even assign command keys to them.

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

Services appear in the Services submenu of each application menu, and within the contextual menu (Control-Click or Right-Click on a folder or pathname).

服务出现在每个应用程序菜单的服务子菜单和上下文菜单中(按住 Control 单击或右键单击文件夹或路径名)。

The New Terminal at Folderservice will become active when you select a folderin Finder. You cannot simply have the folder open and run the service "in place". Go back to the parent folder, select the relevant folder, then activate the service via the Services menu or context menu.

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

In addition, Lion Terminal will open a new terminal window if you drag a folder (or pathname) onto the Terminal application icon, and you can also drag to the tab bar of an existing window to create a new tab.

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

Finally, if you drag a folder or pathname onto a tab (in the tab bar) and the foreground process is the shell, it will automatically execute a "cd" command. (Dragging into the terminal view within the tab merely inserts the pathname on its own, as in older versions of Terminal.)

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

You can also do this from the command line or a shell script:

您也可以从命令行或 shell 脚本执行此操作:

open -a Terminal /path/to/folder

This is the command-line equivalent of dragging a folder/pathname onto the Terminal application icon.

这是将文件夹/路径名拖到终端应用程序图标上的命令行等效项。

On a related note, Lion Terminal also has new Services for looking up man pages: Open man page in Terminaldisplays the selected man page topic in a new terminal window, and Search man Pages in Terminalperforms "apropos" on the selected text. The former also understands man page references ("open(2)"), man page command line arguments ("2 open") and man page URLs ("x-man-page://2/open").

在相关说明中,Lion Terminal 还提供了用于查找手册页的新服务:在终端中打开手册页在新的终端窗口中显示选定的手册页主题,并且在终端中搜索手册页对选定的文本执行“适当”。前者还理解手册页引用(“open(2)”)、手册页命令行参数(“2 open”)和手册页 URL(“x-man-page://2/open”)。

回答by redacted

This:

这:

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

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

It's a small app that you drag into the Finder toolbar, the icon fits in very nicely. It works with Terminal, xterm (under X11), iterm.

这是一个小应用程序,您可以将其拖到 Finder 工具栏中,图标非常适合。它适用于终端、xterm(在 X11 下)、iterm。

回答by Paul Alexander

An application that I've found indispensible as an alternative is DTerm, which actually opens a mini terminal right in your application. Plus it works with just about everything out there - Finder, XCode, PhotoShop, etc.

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

回答by PCheese

Clarification (thanks @vgm64): if you're already in Terminal, this lets you quickly change to the topmost Finder window without leaving Terminal. This way, you can avoid using the mouse.

澄清(感谢@vgm64):如果您已经在终端中,这可以让您快速切换到最顶层的 Finder 窗口,而无需离开终端。这样,您就可以避免使用鼠标。

I've added the following to my .bash_profileso I can type cdffin Terminal at any time.

我已将以下内容添加到我的中,.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 $@`"; };

This is from this macosxhints.com Terminal hint.

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

回答by physicsmichael

Check out Open Terminal Here. It may be the most similar to "Open Command Window Here." I used >cdtoand this is very similar but this seems to be a little better at dealing with Spaces... but not perfect.

在这里查看打开终端。它可能与“在此处打开命令窗口”最相似。我使用过>cdto,这非常相似,但这似乎在处理空间方面要好一些……但并不完美。

What it has that is very nice is the ability to "detect key-down events at the start of the application and used them to modify the behavior of the script" allowing the script to open a new tab in the front most terminal window when invoked by holding down ? key. Neat trick.

它具有的非常好的功能是“在应用程序启动时检测按键事件并使用它们来修改脚本的行为”,允许脚本在调用时在最前面的终端窗口中打开一个新选项卡通过按住?钥匙。巧妙的把戏。

Also note PCheese's answer; it is probably more useful for heavy terminal users!

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

回答by pklaus

There is an updated version of the very nice and slim Open Terminal Hereposted by vgm64and d0k. The change was made by james david low. He published the new version on his site. Just download OpenTerminalHere.zip, extract it, move the bundle to your Library/Scripts folder and drag it from there to your Finder toolbar.

vgm64d0k在这里发布了非常漂亮和纤薄的Open Terminal的更新版本。更改是由詹姆斯大卫低。他在他的网站上发布了新版本。只需下载 OpenTerminalHere.zip,解压缩,将包移动到您的 Library/Scripts 文件夹,然后将其从那里拖到您的 Finder 工具栏。

What is special about it is that it always opens a new tabif a Terminal.app window is already open. Very useful! I also noted that the style of the button of the application better fits the Snow Leopard Finder.app style than cdto posted by redacteddid.

它的特别之处在于,如果 Terminal.app 窗口已经打开,它总是会打开一个新选项卡。很有用!我还注意到,该应用程序的按钮的风格更符合雪豹Finder.app款式比cdto发表节录一样。

回答by Henrik Hartz

Also, you can copy an item from the finder using command-C, jump into the Terminal (e.g. using Spotlight or QuickSilver) type 'cd ' and simply paste with command-v

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

回答by stigi

I created a bundle with 3 apps for the finder toolbar. The other two apps do:

我为 finder 工具栏创建了一个包含 3 个应用程序的包。其他两个应用程序执行以下操作:

  • open Textmate with the current selection
  • open GitX with the current folder
  • 使用当前选择打开 Textmate
  • 使用当前文件夹打开 GitX

For more information see here: http://nslog.de/posts/71

有关更多信息,请参见此处:http: //nslog.de/posts/71

回答by iayork

If you install Big Cat Scripts (http://www.ranchero.com/bigcat/) you can add your own contextual menu (right click) items. I don't think it comes with an Open Terminal Here applescript but I use this script (which I don't honestly remember if I wrote myself, or lifted from someone else's example):

如果您安装 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


Similar scripts can also get you the complete path to a file on right-click, which is even more useful, I find.

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

回答by iayork

It's a bit more than you're asking for, but I recommend Cocoatech's Path Finder for anyone who wishes the Finder had a bit more juice. It includes a toolbar button to open a Terminal window for the current directory, or a retractable pane with a Terminal command line at the bottom of each Finder window. Plus many other features that I now can't live without. Very mature, stable software. http://cocoatech.com/

这比您要求的要多一些,但我向希望 Finder 多一点果汁的人推荐 Cocoatech 的 Path Finder。它包括一个工具栏按钮,用于打开当前目录的终端窗口,或在每个 Finder 窗口底部带有终端命令行的可伸缩窗格。加上我现在离不开的许多其他功能。非常成熟、稳定的软件。 http://cocoatech.com/