Droplets

Droplets are specialized AppleScript applets which are designed to process items dragged onto them. Their icon contains a downward pointing arrow indicating their status as a droplet.

Droplets are written in a specific manner using the on open handler. The following examples can be used as templates for easily creating your own droplets.

If you prefer, you can download a complete set of pre-formed script droplet templates for files, folders, images, and movies.


Droplet for Processing Dragged-on Files

This droplet will process only files which have been dragged onto its icon. It will not process folders, alias files, or files within folders.

To use this sub-routine, put the file types of the files you want to process into the empty type_list list, the matching name extensions into the empty extension_list list, the matching type identifiers into the typeIDs_list,and put your file processing routines within the process_item sub-routine.

Click to open example in the Script Editor applicationA droplet that will process dragged-on files of specified tyes:
 

property type_list : {} -- eg: {"PICT", "JPEG", "TIFF", "GIFf"}
property extension_list : {} -- eg: {"txt", "text", "jpg", "jpeg"}, NOT: {".txt", ".text", ".jpg", ".jpeg"}
property typeIDs_list : {} -- eg: {"public.jpeg", "public.tiff", "public.png"}

-- This droplet processes files dropped onto the applet
on open these_items
 repeat with i from 1 to the count of these_items
 set this_item to item i of these_items
 set the item_info to info for this_item
 try
 set this_extension to the name extension of this_info
 on error
 set this_extension to ""
 end try
 try
 set this_filetype to the file type of this_info
 on error
 set this_filetype to ""
 end try
 try
 set this_typeID to the type identifier of this_info
 on error
 set this_typeID to ""
 end try
 if (folder of the item_info is false) and (alias of the item_info is false) and ¬
 ((this_filetype is in the type_list) or (this_extension is in the extension_list) or ¬
 (this_typeID is in typeIDs_list)) then
 process_item(this_item)
 end if
 end repeat
end open

-- this sub-routine processes files
on process_item(this_item)
 -- NOTE that the variable this_item is a file reference in alias format
 -- FILE PROCESSING STATEMENTS GOES HERE
end process_item


Droplet for Processing Dragged-on Files and Folder Containing Files and Folders

This droplet will process files which have been dragged onto its icon, as well as look inside folders and folders within folders for files which match the indicated file types.

To use this sub-routine, put the file types of the files you want to process into the empty type_list list, the matching name extensions into the empty extension_list list, the matching type identifiers into the typeIDs_list,and put your file processing routines within the process_item sub-routine.

Click to open example in the Script Editor applicationA script droplet that processes recursively through folder hierarchies:
 

property type_list : {} -- eg: {"PICT", "JPEG", "TIFF", "GIFf"}
property extension_list : {} -- eg: {"txt", "text", "jpg", "jpeg"}, NOT: {".txt", ".text", ".jpg", ".jpeg"}
property typeIDs_list : {} -- eg: {"public.jpeg", "public.tiff", "public.png"}

-- This droplet processes files dropped onto the applet
on open these_items
 repeat with i from 1 to the count of these_items
 set this_item to item i of these_items
 set the item_info to info for this_item
 if folder of the item_info is true then
 process_folder(this_item)
 else
 try
 set this_extension to the name extension of item_info
 on error
 set this_extension to ""
 end try
 try
 set this_filetype to the file type of item_info
 on error
 set this_filetype to ""
 end try
 try
 set this_typeID to the type identifier of item_info
 on error
 set this_typeID to ""
 end try
 if (folder of the item_info is false) and (alias of the item_info is false) and ¬
 ((this_filetype is in the type_list) or (this_extension is in the extension_list) or ¬
 (this_typeID is in typeIDs_list)) then
 process_item(this_item)
 end if
 end if
 end repeat
end open

-- this sub-routine processes folders
on process_folder(this_folder)
 set these_items to list folder this_folder without invisibles
 repeat with i from 1 to the count of these_items
 set this_item to alias ((this_folder as Unicode text) & (item i of these_items))
 set the item_info to info for this_item
 if folder of the item_info is true then
 process_folder(this_item)
 else
 try
 set this_extension to the name extension of item_info
 on error
 set this_extension to ""
 end try
 try
 set this_filetype to the file type of item_info
 on error
 set this_filetype to ""
 end try
 try
 set this_typeID to the type identifier of item_info
 on error
 set this_typeID to ""
 end try
 if (alias of the item_info is false) and ((this_filetype is in the type_list) or ¬
 (this_extension is in the extension_list) or (this_typeID is in typeIDs_list)) then
 process_item(this_item)
 end if
 end if
 end repeat
end process_folder

-- this sub-routine processes files
on process_item(this_item)
 -- NOTE that the variable this_item is a file reference in alias format
 -- FILE PROCESSING STATEMENTS GOES HERE
end process_item