- AppleScript: how to get the current directory of the topmost Terminal
- tell application "Terminal"
- do shell script "fuser " & (tty of front tab of front window)
- end tell
- #!/bin/bash
- function pwdx {
- lsof -a -p $1 -d cwd -n | tail -1 | awk '{print $NF}'
- }
- for pid in $(osascript "$(dirname "$0")/get_foregroundterminal_proclist.scpt"); do
- pwdx $pid
- break # break on first
- done