获取iTerm位置Applescript

获取iTerm位置Applescript,applescript,Applescript,我想知道如何使用Applescript在iTerm中获取当前会话的当前位置 我试过各种各样的东西。这本词典对我来说很难理解 这是我的最新尝试 tell application "iTerm" tell the current session of current terminal set theSelection to attachment file name display dialog theSelection

我想知道如何使用Applescript在iTerm中获取当前会话的当前位置

我试过各种各样的东西。这本词典对我来说很难理解

这是我的最新尝试

tell application "iTerm"
        tell the current session of current terminal
            set theSelection to attachment file name
            display dialog theSelection
        end tell

    end tell
由此产生的误差是:

error "iTerm got an error: Can’t get file name of current session of current terminal." number -1728 from file name of current session of current terminal

我只想知道iTerm会话当前所在的位置:
/Users/supercolguy/Desktop

该信息当前无法通过iTerm的AppleScript界面获得。会话对象的唯一公开属性与其中运行的内容(与其视觉外观相反)有关,它们是
内容
tty
,而这些不是您在这里寻找的内容。

这很难看

tell application "iTerm"
    if not (exists terminal 1) then reopen
    set mySession to current terminal's current session
    tell mySession
        write text "pwd"
        set sessionContents to it's text
    end tell
end tell

set myPath to paragraph -2 of (do shell script "grep . <<< " & quoted form of sessionContents)
告诉应用程序“iTerm”
如果不存在(终端1),则重新打开
将mySession设置为当前终端的当前会话
告诉我会话
写文本“pwd”
将sessionContents设置为其文本
结束语
结束语

将myPath设置为(do shell script“grep.的第2段。如果有人无意中发现了这个问题,现在还有另一个选项。使用它,您可以使用iTerm定义的变量
会话访问AppleScript中的路径。path

activate application "iTerm"
tell application "iTerm"
    tell current session of current window
        set myTerm to (variable named "session.path")
        write text "echo this is the current path: " & myTerm
    end tell
end tell

我可以运行类似于“pwd”的程序并返回结果吗?只有当您知道用户在shell提示符下时才可以。例如,如果他们正在运行文本编辑器,在终端中键入“pwd”并不能达到您的预期效果。即使他们在shell提示符下,在屏幕上查找输出也会很复杂。请告诉我:)我想这很容易。我可以推测它们将在iTerm或Terminal中。我得到了
write text“pwd“
但如何获取该返回值?您必须等待片刻,等待它运行,然后在会话的
内容中搜索输出。这是一个混乱、不可靠的过程;如果可以的话,我会避免的!确实是:)什么是
grep.>>做什么?我知道grep本身做什么,只是从来没有见过这样的情况。当我测试脚本时,contents(它的文本)返回终端的文本,后跟几个尾随的换行符。grep命令删除换行符,以确保倒数第二段返回的是路径,而不是空行。好的ol hack+1,为我工作,在写入后不得不延迟0.1,因为有时was内容没有立即更新。它起作用了我只是想请你解释一下,以供我自己参考。:)谢谢谢谢你的帮助