Skip to main content ramblings of a lost one

Orgmode Image Insert on Windows 10

My workflow relies on orgmode, currently (may change 1) all orgfiles for each project reside in a top level folder and then i create a subfolder for each project into which all data is stored (emails\images\project files etc) and the org file links to these eg;

~ top level folder

  • project 1 orgfile
  • project 2 orgfile
  • project_1_data
    • email_1_for_project_1
    • image_for_project_1
  • project_2_data
    • email_1_for_project_2
    • image_for_project_2

When it comes to image capture i either launch greenshot and save everything to a temporary capture folder or launch the windows snipping tool & then choose where to save the image the issue with this workflow is that its not smooth. After i have captured the image there is another or several steps to insert the image into the main org file and hence become usuable.

Being avid consumer of knowledge i’m constantly searching ways to improve myself and the things i do and have recently been investigating orgroam and so stumbled across nobiot’s github blog on emacs in Windows 10 Zero to Emacs and Org-roam aimed at Windows users. In there he has code to launch the snipping tool and insert a link into the org folder although he has it looking specifically for an images folder. The first lot of code worked out of the box but i could not get the folder chooser section at the end of his blog page to work. Probably just me being dumb ¯\_(ツ)_/¯ but no matter what i tried it just wouldn’t gel so i attempted to fudge my own version and ended up with the following;

emacs-lisp code snippet start

(defun my/take-screenshot ()
  "Take a screenshot into a time stamped unique-named file in the
 directory of your choice, in my case I use helm to traverse & select then insert a link to this file."
  (interactive)
  (let* ((dirname (file-relative-name
               (read-directory-name  "Choose the image directory: "))))
       (setq filename (concat dirname
                      (format-time-string "%Y%m%d%H%M") ".png")))
       ;; (setq filename (concat default-directory
       ;;                (format-time-string "%Y%m%d%H%M") ".png"))
      (shell-command "snippingtool /clip")
      (shell-command (concat "powershell -command \"Add-Type -AssemblyName System.Windows.Forms;if ($([System.Windows.Forms.Clipboard]::ContainsImage())) {$image = [System.Windows.Forms.Clipboard]::GetImage();[System.Drawing.Bitmap]$image.Save('" filename "',[System.Drawing.Imaging.ImageFormat]::Png); Write-Output 'clipboard content saved as file'} else {Write-Output 'clipboard does not contain image data'}\""))
      (insert (concat "[[file:" filename"]]"))
  )

emacs-lisp code snippet end

So far it seems to work well though i’ve yet to put it too intensive use. Feel free to try it, i cant take any credit for it as the idea and code mostly came from nobiot.


  1. instead of having the org file residing in the top level directory i may simply create the project folder as normal and store the org file within it along with all notes\emails\images etc ↩︎