AppleScript的:如何获得最顶层终端的当前目录 [英] AppleScript: how to get the current directory of the topmost Terminal

查看:413
本文介绍了AppleScript的:如何获得最顶层终端的当前目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要得到的最顶层终端标签/窗口的当前目录(通过AppleScript的或别的东西,它并不真正的问题)。我该怎么做?

I want to get the current directory of the topmost Terminal tab/window (via AppleScript or something else, it doesn't really matter). How can I do that?

推荐答案

另一种解决方案。

get_foregroundterminal_curdir_fast.scpt:

get_foregroundterminal_curdir_fast.scpt:

tell application "Terminal"
    do shell script "lsof -a -p `lsof -a -c bash -u $USER -d 0 -n | tail -n +2 | awk '{if($NF==\"" & (tty of front tab of front window) & "\"){print $2}}'` -d cwd -n | tail -n +2 | awk '{print $NF}'"
end tell

我用 lsof的本身得到相应的终端窗口的bash shell的PID的。这比使用更快的定影(毫秒主场迎战秒)。

I use lsof itself to get PID of the bash shell of the corresponding Terminal window. This is MUCH faster than using fuser (milliseconds vs. seconds).

这篇关于AppleScript的:如何获得最顶层终端的当前目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆