Created
May 22, 2016 18:25
-
-
Save automaticit/b29ebbd513bc4eca038a31f7c43823c7 to your computer and use it in GitHub Desktop.
VMRC Linking in Emacs Org Mode on Macintosh OS X
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; | |
;; Enable vmrc linking in OS X | |
;; Resources: [[http://endlessparentheses.com/use-org-mode-links-for-absolutely-anything.html][Use Org-Mode Links for Absolutely Anything]] | |
;; [[http://blog.manbolo.com/2013/10/25/automating-terminal-tasks-on-osx][Automating Terminal Tasks on OSX]] | |
;; [[http://www.robpeck.com/2010/05/scripting-iterm-with-applescript/#.V0Hz6mYsjcf][Scripting iTerm with AppleScript]] | |
;; [[https://www.iterm2.com/applescript.html][iTerm2 Applescript]] | |
;; [[http://stackoverflow.com/questions/1870270/sending-commands-and-strings-to-terminal-app-with-applescript][Sending commands and strings to Terminal.app with Applescript]] | |
;; [[http://irreal.org/blog/?p=4865][Calling Applescript from Emacs]] | |
;; [[http://pragmaticemacs.com/emacs/search-with-os-x-spotlight-from-emacs/][Search with OS X Spotlight from emacs]] | |
;; [[http://jblevins.org/log/emacs-omnifocus][Sending Tasks to OmniFocus from Emacs]] | |
;; | |
(defun applescript-quote-string (argument) | |
"Quote a string for passing as a string to AppleScript." | |
(if (or (not argument) (string-equal argument "")) | |
"\"\"" | |
;; Quote using double quotes, but escape any existing quotes or | |
;; backslashes in the argument with backslashes. | |
(let ((result "") | |
(start 0) | |
end) | |
(save-match-data | |
(if (or (null (string-match "[^\"\\]" argument)) | |
(< (match-end 0) (length argument))) | |
(while (string-match "[\"\\]" argument start) | |
(setq end (match-beginning 0) | |
result (concat result (substring argument start end) | |
"\\" (substring argument end (1+ end))) | |
start (1+ end)))) | |
(concat "\"" result (substring argument start) "\""))))) | |
(org-add-link-type | |
"vmrc" 'automaticit/follow-vmrc-link) | |
(defun automaticit/follow-vmrc-link (vmrc-link) | |
"Launch VMware Remote Console (VMRC) with VMRC-LINK as argument using OS X open." | |
(do-applescript "tell application \"iTerm\" | |
activate | |
make new terminal | |
tell the current terminal | |
activate first session | |
tell the first session | |
write text \"open vmrc://@ns525551.ip-192-99-63.net:443/?moid=1\" | |
end tell | |
end tell | |
end tell | |
")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment