Copy Emacs File Names To The Mac Clipboard
** TL; DR
This copies the name of the current Emacs buffer to the Mac pasteboard.
(defun copy-buffer-name-to-osx-clipboard ()
(interactive)
(let ((process-connection-type nil))
(let ((proc (start-process "pbcopy" "*Messages*" "pbcopy")))
(process-send-string proc (buffer-file-name))
(process-send-eof proc))))
I load that in my init files and set a hotkey to call it with this :
(global-set-key (kbd "C-M-!") 'copy-buffer-name-to-osx-clipboard)
The original version that just does a copy paste to the pasteboard of whatever is selected came from [[https : //gist.github.com/the - kenny/267162][this gist]]. For completeness, it looks like this :
(defun copy-from-osx ()
(shell-command-to-string "pbpaste"))
(defun paste-to-osx (text &optional push)
(let ((process-connection-type nil))
(let ((proc (start-process "pbcopy" "*Messages*" "pbcopy")))
(process-send-string proc text)
(process-send-eof proc))))
(setq interprogram-cut-function 'paste-to-osx)
(setq interprogram-paste-function 'copy-from-osx))
I use the evil vim binding so I don't need that version. I also don't totally understand how it works. I just know it does.
Reference :
https : //gist.github.com/the - kenny/267162
https : //emacs.stackexchange.com/questions/10900/copy - text - from - emacs - to - os - x - clipboard
~ fin ~