Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
49 lines (36 sloc) 1.73 KB
#!/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
Something went wrong with that request. Please try again.