是否有类似于“在这里打开命令窗口”的Mac OS Windows Powertoy ?我通过谷歌搜索找到了几个插件,但想看看哪些最适合开发人员。
当前回答
在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
其他回答
我主要使用这个函数:
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,他们就会重用该选项卡。
我发现一个不可或缺的替代应用程序是DTerm,它实际上在应用程序中打开了一个迷你终端。另外,它适用于几乎所有的东西- Finder, XCode, PhotoShop等。
我为finder工具栏创建了一个包含3个应用程序的包。 另外两个应用程序可以做到:
打开当前选择的Textmate 用当前文件夹打开GitX
更多信息请看这里: http://nslog.de/posts/71
在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
从Mac OS X Lion 10.7开始,终端就以服务的形式包含了这个功能。与大多数服务一样,这些默认情况下是禁用的,因此您需要启用它才能显示在Services菜单中。
系统首选项>键盘>快捷方式>服务
在文件夹中启用新终端。在文件夹中还有新终端选项卡,它将在最前面的终端窗口中创建一个选项卡(如果有的话,它将创建一个新窗口)。这些服务适用于所有应用程序,而不仅仅是Finder,它们对文件夹和文本中选择的绝对路径名进行操作。
您甚至可以为它们分配命令键。
服务出现在每个应用程序菜单的Services子菜单中,并在上下文菜单中(控制-单击或右键单击文件夹或路径名)。
当您在Finder中选择文件夹时,文件夹处的新终端服务将处于活动状态。您不能简单地打开文件夹并“就地”运行服务。回到父文件夹,选择相关文件夹,然后通过Services菜单或上下文菜单激活服务。
此外,如果你将文件夹(或路径名)拖到终端应用程序图标上,Lion终端将打开一个新的终端窗口,你也可以拖到现有窗口的选项卡栏上创建一个新的选项卡。
最后,如果你将一个文件夹或路径名拖到一个选项卡上(在选项卡栏中),前台进程是shell,它将自动执行一个“cd”命令。(在选项卡中拖拽到终端视图只是单独插入路径名,就像在旧版本的terminal中一样。)
你也可以通过命令行或shell脚本来完成:
open -a Terminal /path/to/folder
这相当于在命令行中将文件夹/路径名拖放到终端应用程序图标上。
与此相关的是,Lion终端还提供了用于查找手册页的新服务:在终端中打开手册页会在新的终端窗口中显示所选的手册页主题,而在终端中搜索手册页则会“恰当地”执行所选文本。前者还理解手册页引用(“open(2)”)、手册页命令行参数(“2 open”)和手册页url(“x-man-page://2/open”)。
推荐文章
- 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用户
- 崇高的文本从命令行