Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to work with WSL? #178

Open
jtpavlock opened this issue Sep 28, 2021 · 8 comments
Open

How to work with WSL? #178

jtpavlock opened this issue Sep 28, 2021 · 8 comments

Comments

@jtpavlock
Copy link

jtpavlock commented Sep 28, 2021

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.

@LesleyLai
Copy link

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.

@wang1zhen
Copy link

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.

@liangzid
Copy link

I have the same problem, I use win10 + wsl2 + mobaxterm, and there is no way to drag or clip images.

@liangzid
Copy link

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.")
    ))

@Awannaphasch2016
Copy link

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?

@sdoyle88
Copy link

sdoyle88 commented Apr 13, 2022

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.

@fkgruber
Copy link

fkgruber commented Dec 29, 2022

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)')\"")
  )

@fkgruber
Copy link

fkgruber commented Jan 1, 2023

any way to be able to use drag and drop?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants