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?
相关问题
- Execute C program till Ctrl+C hit in the terminal
- Gulp BrowserSync showing “reloading browsers” in T
- How to execute a terminal command in Xamarin.Mac a
- JXA Move a message to a different folder/mailbox
- Weird colored terminal response by git [duplicate]
相关文章
- Emacs/xterm color annoyance on Linux
- make GitX open via Terminal for the repo laying at
- Reset bash history search position
- Issues in executing FFmpeg command in Java code in
- output of [31m text instead of color
- How to change the terminal prompt to just current
- Terminal text becomes invisible after terminating
- trouble getting sublime to execute with linux term
Another solution.
get_foregroundterminal_curdir_fast.scpt:
I use
lsof
itself to get PID of the bash shell of the corresponding Terminal window. This is MUCH faster than usingfuser
(milliseconds vs. seconds).Ok, I have one solution.
get_foregroundterminal_proclist.scpt:
get_foregroundterminal_curdir.sh:
I got pointed to the question when posting a question about how to find the current directory in Applescript so I'm posting this answer to let future referred readers know the excepted answer has a flaw in it.
If the current directory path has a SPACE character in it, then it only returns the portion of the path after (the last) SPACE character!
Use this simple script instead, it handles every path:
tell application "Terminal" to set currentDirectory to (do shell script "pwd")