Skip to content

Instantly share code, notes, and snippets.

@lawlist
Last active June 29, 2019 19:14
Show Gist options
  • Save lawlist/9be45ebf53a1458cb4e7d2d6ff5bae38 to your computer and use it in GitHub Desktop.
Save lawlist/9be45ebf53a1458cb4e7d2d6ff5bae38 to your computer and use it in GitHub Desktop.
Call qlmanage and return focus to Emacs.
(require 'dired)
(defun qlmanage-return-focus-to-emacs ()
"Doc-string."
(let* ((filename (dired-get-file-for-visit))
(emacs-executable (concat invocation-directory "Emacs"))
(emacs-script (concat "tell application \"" emacs-executable "\" to activate")))
(set-process-sentinel
(start-process "qlmanage" nil "/usr/bin/qlmanage" "-p" filename)
`(lambda (p e) (when (= 0 (process-exit-status p))
(set-process-sentinel
(start-process "emacs" nil "osascript" "-e" ,emacs-script)
'(lambda (p e) (when (= 0 (process-exit-status p))
(message "Congratulations: %s" ,filename)))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment