Skip to content

Instantly share code, notes, and snippets.

@dreikanter
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dreikanter/cca78cc7ca50070aa5fe to your computer and use it in GitHub Desktop.
Save dreikanter/cca78cc7ca50070aa5fe to your computer and use it in GitHub Desktop.
File renaming action for Dropzone 3
# Dropzone Action Info
# Name: Archive Image
# Description: Save imge to specified forder, and rename it to YYYYMMDD format.
# Handles: Files
# Creator: Alex Musayev
# URL: http://yoursite.com
# Events: Dragged
# KeyModifiers: Command, Option, Control, Shift
# SkipConfig: No
# RunsSandboxed: Yes
# Version: 1.0
# MinDropzoneVersion: 3.0
require 'fileutils'
DEFAULT_ARCHIVE_DIR = '/Users/dreikanter/Dropbox/Images/'
def dragged
archive_dir = File.expand_path(ENV.fetch('IMAGE_ARCHIVE_DIR', DEFAULT_ARCHIVE_DIR))
FileUtils.mkdir_p(archive_dir) unless File.directory? archive_dir
output = []
$items.each do |source_file|
timestamp = File.ctime(source_file).strftime('%Y%m%d-%H%M')
ext = File.extname(source_file).downcase
file_name = File.join(archive_dir, "#{timestamp}#{ext}")
number = 0
while File.exist? file_name do
number += 1
file_name = File.join(archive_dir, "#{timestamp}-#{number}#{ext}")
end
FileUtils.mv(source_file, file_name)
output << file_name
end
$dz.finish(output.join("\n"))
$dz.url(false)
end
def clicked
$dz.url(false)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment