The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Copy Emacs File Names To The Mac Clipboard

TODO: Pull subtitle into page object

** TL; DR

This copies the name of the current Emacs buffer to the Mac pasteboard.

code_start_default_section code_end_default_section

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

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Copy Emacs File Names To The Mac Clipboard

-- p

** TL; DR

-- p

This copies the name of the current Emacs buffer to the Mac pasteboard.

-- code/
-- elisp

(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))))

-- /code

-- p

I load that in my init files and set a hotkey to call it with this:

-- code/
-- elisp

(global-set-key (kbd "C-M-!") 'copy-buffer-name-to-osx-clipboard)

-- /code

-- p

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:

-- code/
-- elisp

(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))

-- /code

-- p

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.

-- p

Reference:

-- p

https://gist.github.com/the-kenny/267162

-- p

https://emacs.stackexchange.com/questions/10900/copy-text-from-emacs-to-os-x-clipboard


-- categories
-- Emacs
-- dotfiles

-- metadata
-- date: 2022-10-23 15:29:45
-- id: 2gy6tant
-- status: published 
-- type: post
-- SCRUBBED_NEO: false
-- site: aws