I've been using shell-pop recently, and it's nice how I can pop to default-directory in term immediately. For the times I'd rather use a dedicated terminal, is it possible to create an equivalent for OSX's Terminal.app?

What I want is to call one function in emacs and launch Terminal.app cd'd automatically to default-directory.

2 Answers 2

(defun my-applescript-fn ()
"Open the Terminal.app, wait a second, and CD to the Emacs default-directory
of current buffer."
    "tell application \"Terminal\"
    delay 1
    do script with command \"cd %s\" in window 1
    on error
    end try
    end tell" default-directory)))
  • Thank you! I don't know if this would be considered off topic, but what is the proper applescript to account for the case of Terminal already running, but with no windows?
    – sooheon
    Commented May 30, 2016 at 19:38
  • It is the in window 1 that prevents a new window from launching. If you remove that, then a new window is created. I'd need to Google how to put in an if/then to test if a window exists . . . :) I've only played around with a few applescripts and am still fairly unfamiliar with the language.
    – lawlist
    Commented May 30, 2016 at 19:40

The applescript version above didn't seem to work for me--this version is also potentially faster since it requires no delay:

(defun brds/open-Terminal-here ()
     (concat "open -a Terminal "
             (shell-quote-argument (expand-file-name
                                    default-directory))) nil nil))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.