Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
7
Help us understand the problem. What is going on with this article?
@Ladicle

クリップボードの画像を出力するpngpasteコマンドとEmacsの連携 (macOS)

More than 1 year has passed since last update.

クリップボードにコピーした画像を出力したいシーンは多々ある。Preview使うとか方法はさまざまだが、Alfredとかターミナルとかから手軽に使うためにはコマンドになってると便利だ。そんなこんなでおすすめなのはpngpaste。インストール方法としてbrewもサポートしてる。

brew install pngpaste

画像のドラック&ドロップ等、Emacsでは殆どのケースをorg-downloadで解決できるが、クリップボードの画像貼り付けはサポートされていない。
そこで、次のようにpngpasteを呼び出す関数を定義して、C-M-yあたりにバインドすると...Emacsのorg-modeでinline-imageを楽に挿入できる。(便利!

(with-eval-after-load "org"
  (defun org-insert-clipboard-image ()
    "Generate png file from a clipboard image and insert a link to current buffer."
    (interactive)
    (let* ((filename
            (concat (file-name-nondirectory (buffer-file-name))
                    "_image/"
                    (format-time-string "%Y%m%d_%H%M%S")
                    ".png")))
      (unless (file-exists-p (file-name-directory filename))
        (make-directory (file-name-directory filename)))
      (shell-command (concat "pngpaste " filename))
      (if (file-exists-p filename)
          (insert (concat "[[file:" filename "]]")))
      (org-display-inline-images)))

  (global-set-key (kbd "C-M-y") 'org-insert-clipboard-image))
7
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Ladicle
Software Engineer I'm developing Kubernetes as a Service :)
zlab
技術で新しい世界へシフトする。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
7
Help us understand the problem. What is going on with this article?