From 0f4d6cf637533e2838ba34c5b7124a27b0d52736 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Helmut=20H=C3=A4nsel?= Date: Thu, 11 Apr 2024 14:18:18 +0200 Subject: [PATCH 1/2] support WSL (windows subsystem for linux) --- src/ImageClipboard.jl | 8 ++++---- src/_powershell.jl | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ImageClipboard.jl b/src/ImageClipboard.jl index c01b8bd..c92e1c7 100644 --- a/src/ImageClipboard.jl +++ b/src/ImageClipboard.jl @@ -27,14 +27,14 @@ function clipboard_img() else error("Please install wlclipboard or xclip to your system") end + elseif Sys.iswindows() || Sys.islinux() && haskey(ENV, "WSLENV") + img = _powershell() elseif Sys.islinux() if _isavailable_xclip() img = _xclip() else error("Please install xclip to your system") end - elseif Sys.iswindows() - img = _powershell() elseif Sys.isapple() img = _osascript() else @@ -57,14 +57,14 @@ function clipboard_img(img::AbstractMatrix{<:Colorant}) else error("Please install wlclipboard or xclip to your system") end + elseif Sys.iswindows() || Sys.islinux() && haskey(ENV, "WSLENV") + _powershell(img) elseif Sys.islinux() if _isavailable_xclip() _xclip(img) else error("Please install xclip to your system") end - elseif Sys.iswindows() - _powershell(img) elseif Sys.isapple() _osascript(img) else diff --git a/src/_powershell.jl b/src/_powershell.jl index 4b2a98e..0bfa068 100644 --- a/src/_powershell.jl +++ b/src/_powershell.jl @@ -12,7 +12,7 @@ function _powershell() addtype = `Add-Type -AssemblyName System.Windows.Forms\;` getimg = `\$img=\[Windows.Forms.Clipboard\]::GetImage\(\)\;` saveimg = `if \(\$img -ne \$null\)\{\$img.Save\(\"$(path_png)\"\)\}` - cmd = `powershell -NoProfile $addtype $getimg $saveimg` + cmd = `powershell.exe -NoProfile $addtype $getimg $saveimg` run(cmd) # Paste from clipboard @@ -44,7 +44,7 @@ function _powershell(img::AbstractMatrix{<:Colorant}) getfile = `\$file = get-item\(\"$(path_png)\"\)\;` getimg = `\$img = \[System.Drawing.Image\]::Fromfile\(\$file\)\;` copyimg = `\[System.Windows.Forms.Clipboard\]::SetImage\(\$img\)\;` - cmd = `powershell -NoProfile $addtype $adddrawing $getfile $getimg $copyimg` + cmd = `powershell.exe -NoProfile $addtype $adddrawing $getfile $getimg $copyimg` run(cmd) end end From 795eabb47f143a6b372de648b1db8d306f8904bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Helmut=20H=C3=A4nsel?= Date: Thu, 11 Apr 2024 17:36:48 +0200 Subject: [PATCH 2/2] fix copying of image to clipboard for WSL --- src/_powershell.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/_powershell.jl b/src/_powershell.jl index 0bfa068..76c1ed4 100644 --- a/src/_powershell.jl +++ b/src/_powershell.jl @@ -33,18 +33,18 @@ Copy an image to clipboard using `powershell` function _powershell(img::AbstractMatrix{<:Colorant}) mktempdir() do dir # Define path - path_png = joinpath(dir, "clipboard.png") + filename = "clipboard.png" # Save image - save(path_png, img) + save(joinpath(dir, filename), img) # Compose command & run addtype = `Add-Type -AssemblyName System.Windows.Forms\;` adddrawing = `\[Reflection.Assembly\]::LoadWithPartialName\(\'System.Drawing\'\)\;` - getfile = `\$file = get-item\(\"$(path_png)\"\)\;` + getfile = `\$file = get-item\(\"$(filename)\"\)\;` getimg = `\$img = \[System.Drawing.Image\]::Fromfile\(\$file\)\;` copyimg = `\[System.Windows.Forms.Clipboard\]::SetImage\(\$img\)\;` - cmd = `powershell.exe -NoProfile $addtype $adddrawing $getfile $getimg $copyimg` + cmd = Cmd(`powershell.exe -NoProfile $addtype $adddrawing $getfile $getimg $copyimg`; dir) run(cmd) end end