Open jtpavlock opened 2 years ago
Yeah, this is such a nice package and I hope there is a way it can work with WSL GUI Emacs. I can still download from the URL, but there is no way to drag-and-drop local images.
Also, the package is brilliant, but the org-download-clipboard
is not working in wsl. Actually, it worked in Windows 10 with system screenshot tool, but after I upgraded to windows 11, org-download-clipboard
generates a 0KB blank file from my system screenshot tool.
I have the same problem, I use win10 + wsl2 + mobaxterm, and there is no way to drag or clip images.
And I have find a solution with the help of windows Powershell, this is the solution function for replacing org-download-clipboard
:
(defun my-yank-image-from-win-clipboard-through-powershell()
"to simplify the logic, use c:/Users/Public as temporary directoy, and move it into current directoy"
(interactive)
(let* ((powershell "/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe")
(file-name (format-time-string "screenshot_%Y%m%d_%H%M%S.png"))
;; (file-path-powershell (concat "c:/Users/\$env:USERNAME/" file-name))
(file-path-wsl (concat "./images/" file-name))
)
;; (shell-command (concat powershell " -command \"(Get-Clipboard -Format Image).Save(\\\"C:/Users/\\$env:USERNAME/" file-name "\\\")\""))
(shell-command (concat powershell " -command \"(Get-Clipboard -Format Image).Save(\\\"C:/Users/Public/" file-name "\\\")\""))
(rename-file (concat "/mnt/c/Users/Public/" file-name) file-path-wsl)
(insert (concat "[[file:" file-path-wsl "]]"))
(message "insert DONE.")
))
And I have find a solution with the help of windows Powershell, this is the solution function for replacing
org-download-clipboard
:(defun my-yank-image-from-win-clipboard-through-powershell() "to simplify the logic, use c:/Users/Public as temporary directoy, and move it into current directoy" (interactive) (let* ((powershell "/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe") (file-name (format-time-string "screenshot_%Y%m%d_%H%M%S.png")) ;; (file-path-powershell (concat "c:/Users/\$env:USERNAME/" file-name)) (file-path-wsl (concat "./images/" file-name)) ) ;; (shell-command (concat powershell " -command \"(Get-Clipboard -Format Image).Save(\\\"C:/Users/\\$env:USERNAME/" file-name "\\\")\"")) (shell-command (concat powershell " -command \"(Get-Clipboard -Format Image).Save(\\\"C:/Users/Public/" file-name "\\\")\"")) (rename-file (concat "/mnt/c/Users/Public/" file-name) file-path-wsl) (insert (concat "[[file:" file-path-wsl "]]")) (message "insert DONE.") ))
I have 0 knowledge about powershell, but from reading and experimenting, I found that the powershell command that you use doesn't save image and it also doesn't produce any error. I use 5.1 version. Can you help me formulate powershell command that would work on 5.1 version?
I stumbled upon this as I was looking for a similar solution, and this function will work on WSL2 (I am running Ubuntu 20.04). Ensure that the pathing is right, particularly to the powershell command (/mnt/c/Windows/System32/...), the file-path-wsl concat path, and the shell and rename commands.
For example, I changed my file-path-wsl to be "~/GDrive/emacs/org-download-images/".
The powershell .exe hosted in System32 under v1.0 is Powershell 5.1 on Windows systems. Powershell 6+ is Powershell core and usually stored under Program Files. Also, the Get-Clipboard cmdlet in Powershell6+ doesnt support the Image format (yet), just Raw data, so you would want to utilize powershell 5.1 (as mentioned in the code above) if you want a built in cmdlet that can do that conversion.
I wanted to continue using org-download so I just changed the org-download-screenshot-method:
(use-package org-download
:after org
:bind
(:map org-mode-map
(
("C-M-S-Y" . org-download-screenshot)
)
)
:custom
(org-download-screenshot-method "powershell.exe -Command \"(Get-Clipboard -Format image).Save('$(wslpath -w %s)')\"")
)
any way to be able to use drag and drop?
Does anyone have any success or tips for using this package when running Emacs in WSL? It doesn't appear to work out of the box.