是否有类似于“在这里打开命令窗口”的Mac OS Windows Powertoy ?我通过谷歌搜索找到了几个插件,但想看看哪些最适合开发人员。
当前回答
如果你安装了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
类似的脚本还可以通过右键单击获得文件的完整路径,我发现这更有用。
其他回答
在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
如果你安装了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
类似的脚本还可以通过右键单击获得文件的完整路径,我发现这更有用。
澄清(感谢@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的终端提示。
我发现一个不可或缺的替代应用程序是DTerm,它实际上在应用程序中打开了一个迷你终端。另外,它适用于几乎所有的东西- Finder, XCode, PhotoShop等。
好吧,我意识到有点晚了…也许在我写这篇文章的时候,这个选择还不存在?
不管怎样,我发现通过Fink安装pos包是最简单的解决方案(在这种情况下是先决条件,也许使用MacPorts的人也有类似的方法?)你会得到两个命令:
posd -给出最前端Finder窗口的当前目录(您可以为其创建一个别名cdf=cd posd) fdc -将最前面的Finder窗口的当前目录切换到终端pwd。这与“open .”略有不同,后者总是打开一个新的finder窗口。
是的,在写cdf之前你必须切换到终端窗口,但我认为这比在Finder工具栏中单击一个按钮要便宜得多。它也适用于iTerm,你不需要下载一个单独的Finder工具栏按钮来打开一个iTerm窗口。这与PCheese提出的方法相同,但是您不必使.bash_profile变得混乱。
推荐文章
- NSRange从Swift Range?
- 如何在交互式Python中查看整个命令历史?
- 在OSX中永久设置PATH环境变量
- 如何停止mysqld
- Git显示“警告:永久添加到已知主机列表”
- 如何从远程SSH会话发送数据到本地剪贴板
- Docker- compose无法连接到Docker Daemon
- SSH端口转发~/。ssh /配置文件?
- 如何复制文件跨计算机使用SSH和MAC OS X终端
- Mac SQLite编辑器
- 在MacOS X上推荐用什么方式安装Node.js、nvm和npm ?
- 如何在Swift中删除视图的所有子视图?
- 如何在Mac OS Lion上从命令行启动MySQL服务器?
- 警告用户/local/mysql/data目录不属于mysql用户
- 崇高的文本从命令行