From f124f4484d4641c673ded50ae82602cf90e85436 Mon Sep 17 00:00:00 2001 From: hyrodium Date: Tue, 15 Jun 2021 21:58:16 +0900 Subject: [PATCH 1/2] add support for mac --- src/ImageClipboard.jl | 6 +++++- src/_osascript.jl | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/_osascript.jl diff --git a/src/ImageClipboard.jl b/src/ImageClipboard.jl index 762f825..46c62ea 100644 --- a/src/ImageClipboard.jl +++ b/src/ImageClipboard.jl @@ -9,7 +9,7 @@ include("_xclip.jl") # linux-wayland include("_wlclipboard.jl") # mac -# include("_osascript.jl") +include("_osascript.jl") # windows include("_powershell.jl") @@ -35,6 +35,8 @@ function clipboard_img() end elseif Sys.iswindows() img = _powershell() + elseif Sys.isapple() + img = _osascript() else error("Currently, only linux and windows are supported") end @@ -63,6 +65,8 @@ function clipboard_img(img::Matrix{<:Colorant}) end elseif Sys.iswindows() _powershell(img) + elseif Sys.isapple() + _osascript(img) else error("Currently, only linux and windows are supported") end diff --git a/src/_osascript.jl b/src/_osascript.jl new file mode 100644 index 0000000..fc5e59b --- /dev/null +++ b/src/_osascript.jl @@ -0,0 +1,42 @@ +""" + _osascript() -> Matrix{<:Colorant} + +Paste an image from clipboard using osascript +""" +function _osascript() + mktempdir() do dir + # Define path + path_png = joinpath(dir, "clipboard.png") + + # Compose command & run + cmd = Cmd(["osascript", "-e", "write (the clipboard as «class PNGf») to (open for access \"$(path_png)\" with write permission)"]) + run(cmd) + + # Paste from clipboard + if isfile(path_png) + img = load(path_png) + return img + else + error("No image in clipboard") + end + end +end + +""" + _osascript(img::Matrix{<:Colorant}) + +Copy an image to clipboard using osascript +""" +function _osascript(img::Matrix{<:Colorant}) + mktempdir() do dir + # Define path + path_png = joinpath(dir, "clipboard.png") + + # Save image + save(path_png, img) + + # Compose command & run + cmd = Cmd(["osascript", "-e", "set the clipboard to (read \"$(path_png)\" as «class PNGf»)"]) + run(cmd) + end +end From 904674ff698a9af1a6d2112dd4b0ef8320f5d7b5 Mon Sep 17 00:00:00 2001 From: hyrodium Date: Tue, 15 Jun 2021 22:05:44 +0900 Subject: [PATCH 2/2] update ci to support mac --- .github/workflows/CI.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 9639b2a..1c3f283 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -15,6 +15,7 @@ jobs: os: - ubuntu-latest - windows-latest + - macos-latest arch: - x64 include: