Macos 在Mac OS finder中打开终端

Macos 在Mac OS finder中打开终端,macos,terminal,finder,Macos,Terminal,Finder,是否有类似于“在此处打开命令窗口”的Windows Powertoy for Mac OS?我通过谷歌搜索找到了几个插件,但想看看哪些插件最适合开发人员。此外,如果你安装了大猫脚本()您可以添加自己的上下文菜单(右键单击)项。我不认为它在这里有一个开放终端applescript,但我使用这个脚本(我真的不记得是我自己写的,还是从别人的例子中提取的): 类似的脚本还可以通过右键单击获得文件的完整路径,我发现这更有用 这是: 这是一个小应用程序,你可以将它拖到Finder工具栏中,图标非常适合

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

此外,如果你安装了大猫脚本()您可以添加自己的上下文菜单(右键单击)项。我不认为它在这里有一个开放终端applescript,但我使用这个脚本(我真的不记得是我自己写的,还是从别人的例子中提取的):



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

这是:

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

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

我已将以下内容添加到我的
.bash\u配置文件中
,以便我可以随时在终端中键入
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 $@`"; };
函数ff{osascript-e'告诉应用程序“Finder”'\

-e“如果(${1-1}这比你要求的要多了一点,但是我推荐Cocoatech的路径查找器给那些希望查找器更有活力的人。它包括一个工具栏按钮,用于打开当前目录的终端窗口,或者一个可伸缩的窗格,在每个查找器窗口的底部都有一个终端命令行。还有许多其他我现在无法实现的功能我不能没有。非常成熟、稳定的软件。

请检查。它可能与“在此处打开命令窗口”最为相似。我使用了
>cdto
,这非常相似,但在处理空格方面似乎有点更好……但并不完美

它所具有的非常好的功能是“在应用程序开始时检测按键关闭事件,并使用它们修改脚本的行为”,允许脚本在按住键调用时在最前面的终端窗口中打开一个新选项卡⌘ 钥匙,漂亮的把戏


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

好的,我意识到这有点晚了……也许在写这篇文章的时候,这个替代方案不可用

无论如何,我发现通过Fink安装pos软件包是最简单的解决方案(在本例中,这是一个先决条件,对于使用MacPorts的人来说,可能有类似的解决方案)。您可以使用两个命令:

  • posd-提供最前面的Finder窗口的当前目录(您可能会为其创建别名cdf=cd posd)
  • fdc-将最前面的查找器窗口的当前目录切换到终端pwd。这与“打开”略有不同。后者总是打开一个新的查找器窗口

  • 是的,您必须在编写cdf之前切换到终端窗口,但我认为这与单击Finder工具栏中的按钮相比非常便宜。而且它也适用于iTerm,您不必下载打开iTerm窗口的单独Finder工具栏按钮。这与PCheese提出的方法相同,但您不必下载混乱您的.bash_配置文件。

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

    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个应用程序的包。 其他两个应用程序可以:

    • 打开与当前所选内容匹配的文本
    • 使用当前文件夹打开GitX
    有关更多信息,请参见此处:

    这里有一个由vgm64和d0k发布的非常小巧的开放终端的更新版本。更改由james david low完成。他于发布了新版本。只需下载OpenTerminalHere.zip,解压缩它,将捆绑包移动到您的Library/Scripts文件夹,并将其从那里拖到Finder工具栏


    它的特别之处在于,如果Terminal.app窗口已经打开,它总是会打开一个新的选项卡。非常有用!我还注意到,该应用程序的按钮样式更适合Snow Leopard Finder.app样式,而不是Redact发布的cdto样式。

    我发现作为替代方案必不可少的一个应用程序是,它实际上会在你的应用程序中打开一个迷你终端。此外,它几乎可以与任何东西一起工作-Finder、XCode、PhotoShop等。

    如果像我一样关闭Finder工具栏,此服务会在每个文件夹的上下文菜单中添加一个项目:


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

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

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

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

    您甚至可以为它们指定命令键

    服务显示在每个应用程序菜单的“服务”子菜单中,以及上下文菜单中(控制单击或右键单击文件夹或路径名)

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

    此外,狮子T
    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
    
    open -a Terminal /path/to/folder
    
    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
    
    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