macos - Mac 终端将目录更改为当前的前端查找器窗口

标签 macos unix terminal

关闭。这个问题不符合 Stack Overflow guidelines 。它目前不接受答案。












想改善这个问题吗?更新问题,使其成为 Stack Overflow 的 on-topic

2年前关闭。




Improve this question




标题说明了一切。我只想知道输入什么命令将工作目录更改为在前查找器窗口中打开的目录。

最佳答案

我的回答基于对类似 question about how to get the path of the front-most window in Objective-C and Cocoa 的回答(这显然来自 Mac OS X Hints 提示,这可能是您的确切问题)。我已经测试了该命令,它也可以使用包含空格的目录路径。

cd "`osascript -e 'tell application "Finder" to POSIX path of (target of window 1 as alias)'`"

使用 bash? 将此功能添加到您的 bash 配置文件中。
cdf () {
  finderPath=`osascript -e 'tell application "Finder"
                               try
                                   set currentFolder to (folder of the front window as alias)
                               on error
                                   set currentFolder to (path to desktop folder as alias)
                               end try
                               POSIX path of currentFolder  
                            end tell'`;
  cd "$finderPath"
}

关于macos - Mac 终端将目录更改为当前的前端查找器窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18456682/

相关文章:

terminal - oh-my-zsh:达到 git 最大嵌套函数级别

linux - 使用 sed 在模式后添加文本,但添加的文本来自列表文件

Python:在 linux 终端中获取最后一个命令行

objective-c - Mac App Store 评论员说 "It appears Kiwi fails codesign verification"

bash - 等待在 Bash 中创建文件

linux - 在Unix中,如果用户从特定IP(或主机)登录,如何显示欢迎消息?

bash - tr -d 从字符串中删除精确的字符串

c++ - 在 Mac 上安装 xgboost 失败 - ar : no archive members specified

macos - CFRunLoopRun() 与 [NSRunLoop 运行]

ruby - 如何在 OSX Mavericks 上安装命令行工具