3

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.

4
(defun my-applescript-fn ()
"Open the Terminal.app, wait a second, and CD to the Emacs default-directory
of current buffer."
(interactive)
(do-applescript
  (format
    "tell application \"Terminal\"
    activate
    delay 1
    try
    do script with command \"cd %s\" in window 1
    on error
    beep
    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 May 30 '16 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 May 30 '16 at 19:40
0

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 ()
    (interactive)
    (shell-command
     (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, privacy policy and cookie policy

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