OTHER FOLDER ACTION SCRIPTS

1) Archive Added Items

This script will make an archived copy, in ZIP format, of the individual items added to the attached folder. Archived files are placed in folder named "Done" within the attached folder.

click for script
on adding folder items to this_folder after receiving these_items
tell application "Finder"
if not (exists folder "Done" of this_folder) then
make new folder at this_folder with properties {name:"Done"}
end if
set the destination_folder to folder "Done" of this_folder as alias
set the destination_directory to POSIX path of the destination_folder
end tell
repeat with i from 1 to number of items in these_items
set this_item to item i of these_items
set the item_info to info for this_item
if this_item is not the destination_folder and the name extension of ¬
the item_info is not in {"zip", "sit"} then
set the item_path to the quoted form of the POSIX path of this_item
set the destination_path to the quoted form of ¬
(destination_directory & (name of the item_info) & ".zip")
do shell script ("/usr/bin/ditto -c -k -rsrc --keepParent " & ¬
item_path & " " & destination_path)
end if
end repeat
end adding folder items to


2) Auto-backup Script

This script will automatically backup specified items any time a particular hard drive is mounted on the desktop.

How the Script Works
When a backup drive is mounted on the desktop, the system automatically creates an alias file to it in the invisible Volumes folder. This action will trigger the Folder Action script which will then look in the Home directory for the Auto Backup folder and iterate its contents looking for an alias file that matches the one just added to the Volumes folder.

If a match is found (indicating the backup drive has been mounted), the script them generates a list of all the original items of the other alias files in the Auto Backup folder and proceeds to duplicate the originial items to the specified folder on the backup drive. Once the task has been completed, the backup drive will be automatically unmounted.

To use this script, follow these steps:
  1. Copy this script into a new script window. Optinally, you change any of the property values in the script to adjust it for your needs.
  2. Save this script into the Folder Actions Scripts folder.
  3. Create a folder in your Home directory named "Auto Backup."
  4. Create an alias file to the backup disk and place it in the folder.
  5. Place alias files of the items you wish to backup in the "Auto Backup" folder.
  6. With a new Finder window open, select Go to folder... from the Finder's Go menu. Enter "/Volumes/" (without quotes) in the text field on the drop-down sheet dialog and click the Go button. The Volumes folder opens in the Finder window. IMPORTANT: do not delete or add anything to this folder.
  7. Launch the Folder Actions Setup utility.
  8. In the Folder Actions Setup utility window click the Add Folder Action button at the bottom left. The button is round and has a plus-sign in it ( + ).
  9. Drag the small folder icon from the Finder window title bar into the Choose Folder sheet dialog. The Volumes folder will now become the current selection. AClick the OK button in the Folder Actions Setup dialog.
  10. From the forthcoming list dialog sheet, choose the backup script you saved into the Folder Actions Scripts folder.
  11. Close the Finder window.

property backup_foldername : "Auto Backup"
property destination_foldername : "Backup Folder"
property eject_when_done : true
property confirm_backup : true

on adding folder items to this_folder after receiving these_volumes
tell application "Finder"
activate
try
if not (exists folder backup_foldername of home) then
error "This backup Folder Action script cannot continue " & ¬
"because the folder \"" & ¬
backup_foldername & "\" does not exist in the home directory."
end if
set the source_folder to folder backup_foldername of home
-- get a list of alias files in the source folder
set the alias_list to every alias file of the source_folder
-- check to see if any of the alias files link to a disk
repeat with i from 1 to number of items in alias_list
set this_aliasfile to item i of alias_list
try
set this_item to the original item of this_aliasfile
if the kind of this_item is "Volume" then
set this_disk to (this_item as alias)
if this_disk is in these_volumes then
-- BACKUP THE FOLDER
-- generate a list of items to backup
set the backup_items to {}
repeat with q from 1 to number of items in alias_list
try
set this_item to the original item of item q of alias_list
if the kind of this_item is not "Volume" then
set the end of the backup_items to this_item
end if
end try
end repeat
if the backup_items is {} then ¬
error "No items were found to backup."
if not (exists folder destination_foldername of this_disk) then
make new folder at this_disk ¬
with properties {name:destination_foldername}
end if
if confirm_backup is true then
display dialog "Backup folder \"" & ¬
backup_foldername & "\"?" giving up after 30
if the button returned of the result is "" then ¬
error number -128
end if
with timeout of 3600 seconds
duplicate the backup_items to ¬
folder destination_foldername of this_disk with replacing
end timeout
if eject_when_done is true then
eject this_disk
end if
exit repeat
end if
end if
end try
end repeat
on error error_message number error_number
if the error_number is not -128 then
display dialog error_message buttons {"OK"} default button 1
end if
end try
end tell
end adding folder items to



Next Page
TABLE OF CONTENTS

Introduction

Contextual Finder Menu - Setting up Folder Actions in the Finder

Folder Actions Setup - A utility for administering Folder Actions

Writing Folder Actions - How to write Folder Actions scripts

Installed Scripts - A description of the installed Folder Actions scripts

Example Scripts - Other examples of Folder Actions scripts