-
Notifications
You must be signed in to change notification settings - Fork 3
/
_osascript.jl
42 lines (35 loc) · 1.06 KB
/
_osascript.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
_osascript() -> AbstractMatrix{<: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", "try\nwrite (the clipboard as «class PNGf») to (open for access \"$(path_png)\" with write permission)\nend try"])
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::AbstractMatrix{<:Colorant})
Copy an image to clipboard using `osascript`
"""
function _osascript(img::AbstractMatrix{<: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