Skip to content

Instantly share code, notes, and snippets.

@tequilasunset
Created January 4, 2011 13:10
Show Gist options
  • Save tequilasunset/764745 to your computer and use it in GitHub Desktop.
Save tequilasunset/764745 to your computer and use it in GitHub Desktop.
(defun do-applescript+ (&rest scripts)
"Like `do-applescript', but execute concatenated SCRIPTS.
In case the execution fails, return an error."
(condition-case err
(do-applescript
(apply 'concat scripts))
(error err)))
(defun show-in-finder (&optional path behind)
"Display current file/directory in a Finder window"
(interactive)
(let ((item (or path
buffer-file-name
(and (eq major-mode 'dired-mode) default-directory))))
(cond
((not (stringp item)))
((file-remote-p item)
(error "This item is located on a remote system."))
(t
(setq item (expand-file-name item))
(do-applescript+
"tell application \"Finder\" to select (\""
item
"\" as POSIX file)\n"
(unless behind
"tell application \"Finder\" to activate"))))))
(defun open-terminal (&optional path behind)
"Launch Terminal and go to the relevant directory"
(interactive)
(let ((item (or path default-directory)))
(cond
((not (stringp item)))
((file-remote-p item)
(error "This item is located on a remote system."))
((file-directory-p item)
(setq item (expand-file-name item))
(do-applescript+
"tell application \"Terminal\" to do script "
"with command \"cd \" & quoted form of \""
item
"\"\n"
(unless behind
"tell application \"Terminal\" to activate")))
(t
(error "An error occured")))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment