forked from a4agarwal/dropzone-user-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDesktop Picture.dropzone
49 lines (36 loc) · 1.73 KB
/
Desktop Picture.dropzone
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
43
44
45
46
47
48
49
#!/usr/bin/ruby
# Dropzone Destination Info
# Name: Desktop Picture
# Description: A dropped image will be set as the current desktop background. For second, third, and fourth monitors, hold down Command, Option, and Control respectively.
# Handles: NSFilenamesPboardType
# Events: Dragged
# KeyModifiers: Command, Option, Control
# Creator: cockscomb.info extended by NovaStorm Software
# URL: http://cockscomb.info
# IconURL: http://aptonic.com/destinations/icons/desktop.png
def dragged
$dz.determinate(false)
file_path = $items[0]
file_name = File.basename(file_path)
$dz.begin("Changing to #{file_name}...")
allowed_exts = ["jpg", "jpeg", "gif", "tif", "tiff", "png", "bmp"]
ext = File.extname(file_path).downcase[1..-1]
if allowed_exts.include?(ext)
if ENV['KEY_MODIFIERS'] == "Command"
%x(osascript -e 'tell application "System Events"\n if second desktop exists then\n set picture of second desktop to "#{file_path}"\n end if\n end tell')
$dz.finish("2nd Desktop Changed!")
elsif ENV['KEY_MODIFIERS'] == "Option"
%x(osascript -e 'tell application "System Events"\n if third desktop exists then\n set picture of third desktop to "#{file_path}"\n end if\n end tell')
$dz.finish("3rd Desktop Changed!")
elsif ENV['KEY_MODIFIERS'] == "Control"
%x(osascript -e 'tell application "System Events"\n if fourth desktop exists then\n set picture of fourth desktop to "#{file_path}"\n end if\n end tell')
$dz.finish("4th Desktop Changed!")
else
%x(osascript -e 'tell application "System Events" to set picture of current desktop to "#{file_path}"')
$dz.finish("Changed!")
end
else
$dz.finish("Error")
end
$dz.url(false)
end