
|
|
|
|
|
|
One current limitation is with files that PC users copy to a server, which the script will not act upon. That's because Mac OS will give these PC files a type and creator code of TEXT and DOSA respectively, which the script doesn't recognize. García says that a future version of the script recognize these files and add the proper Mac type and creators.
To create your own AppleScript file, open Script Editor, and paste all the text below the line.
(*
ADD - FIX WINDOWS SUFFIXES
Thomas Garcia - ICON, s.a. - tgarcia@iconsa.com
Parts by: Sal Soghoian ©1998 Apple Computer
This Folder Action script is designed for use with Mac OS 8.5 and higher.
This Folder Action handler is triggered when items are added to the attached folder.
You can alter the default settings of this script by changing the parameters of the properties below.
*)
-- THESE PROPERTIES ARE FOR THE NOTIFICATION ROUTINE
property speak_alert : false -- if true, the script will speak the alert. If false, the script will display an alert dialog
property dialog_timeout : 30 -- set the amount of time before dialogs auto-answer.
-- THIS PROPERTY IS USED TO INDICATE WHETHER THE SCRIPT CHECKS THE INCOMING FILES FOR COMPLETED TRANSFER
-- SET THIS PROPERTY TO TRUE FOR FOLDERS SHARED VIA FILE SHARING
-- NOTE THAT ITEMS DROPPED IN SHARED FOLDERS WILL HAVE THEIR LABEL SET TO 7
property copy_checks_indicator : false
-- THESE PROPERTIES ARE FOR THE STATUS CHECKING ROUTINES
property item_check_delay_time : 2
property folder_check_delay_time : 3
property special_label_index : 7
on «event facofget» this_folder given «class flst»:added_items
try
if copy_checks_indicator is true then
-- CHECK THE FILES TO MAKE SURE THEY"RE COMPLETELY AVAILABLE
set the added_items to my check_added_items(the added_items)
if the added_items is {} then return "no vaild items"
end if
tell application "Finder"
--get the name of the folder
set this_folder_name to the name of this_folder
end tell
-- find out how many new items have been placed in the folder
set new_item_count to the number of items in the added_items
-- CHECKS THE FILENAMES TO SEE IF THEY HAVE THE PROPER SUFFIXES FOR
-- WORD 98, EXCEL 98, POWERPOINT 98, AND FILEMAKER PRO. IF THEY
-- DON'T, CHECKS THE LENGTH OF THE FILENAME AND, IF NECESSARY, TRUNCATES
-- IT ENOUGH TO MAKE SPACE FOR THE PROPER SUFFIX.
tell application "Finder"
repeat with x in added_items
copy name of x as string to FileName
copy file type of x as string to FileType
copy creator type of x as string to FileCreator
copy length of FileName to Filenamelength
-- check for Word 98
if FileType is "W8BN" and FileCreator is "MSWD" then
if FileName does not end with ".doc" then
set Suffix to ".doc"
if Filenamelength > 27 then
set TopLimit to (Filenamelength + (27 - Filenamelength))
copy characters 1 through TopLimit of FileName as string to NewFilename
set NewFilename to NewFilename & Suffix
else
set NewFilename to FileName & Suffix
end if
set the name of x to NewFilename
end if
else
-- check for PowerPoint 98
if FileType is "SLD8" and FileCreator is "PPT3" then
if FileName does not end with ".ppt" then
set Suffix to ".ppt"
if Filenamelength > 27 then
set TopLimit to (Filenamelength + (27 - Filenamelength))
copy characters 1 through TopLimit of FileName as string to NewFilename
set NewFilename to NewFilename & Suffix
else
set NewFilename to FileName & Suffix
end if
set the name of x to NewFilename
end if
else
-- check for Excel 98
if FileType is "XLS8" and FileCreator is "XCEL" then
if FileName does not end with ".xls" then
set Suffix to ".xls"
if Filenamelength > 27 then
set TopLimit to (Filenamelength + (27 - Filenamelength))
copy characters 1 through TopLimit of FileName as string to NewFilename
set NewFilename to NewFilename & Suffix
else
set NewFilename to FileName & Suffix
end if
set the name of x to NewFilename
end if
else
-- check for Filemaker Pro (works with version 3 or 4)
if FileType is "FMP3" and FileCreator is "FMP3" then
if FileName does not end with ".fp3" then
set Suffix to ".fp3"
if Filenamelength > 27 then
set TopLimit to (Filenamelength + (27 - Filenamelength))
copy characters 1 through TopLimit of FileName as string to NewFilename
set NewFilename to NewFilename & Suffix
else
set NewFilename to FileName & Suffix
end if
set the name of x to NewFilename
end if
end if
end if
end if
end if
end repeat
end tell
on error
end try
end «event facofget»
on remove_labels(the added_items)
tell application "Finder"
repeat with this_item in the added_items
set the label index of this_item to 0
end repeat
end tell
end remove_labels
on check_added_items(the added_items)
-- check the transfer status of every added file to determine
-- if each file has completed being moved into the attached folder
set the notbusy_items to {}
repeat with i from 1 to the number of items in the added_items
set this_item to (item i of the added_items)
if my check_busy_status(this_item) is false then
set the end of the notbusy_items to this_item
end if
end repeat
return the notbusy_items
end check_added_items
on check_busy_status(this_item)
-- a folder can contain items partially transfered
-- this routine will wait for all the folder contents to transfer
if the last character of (this_item as text) is ":" then
set the check_flag to false
repeat
-- look for any files within the folder that are still transferring
tell application "Finder"
try
set the busy_items to the name of every file of the entire contents of this_item ¬
whose file type begins with "bzy"
on error
set the busy_items to {}
end try
end tell
if the check_flag is true and the busy_items is {} then return false
-- pause for the indicated time
«event sysodela» the folder_check_delay_time
-- set the flag and check again
set the check_flag to true
end repeat
else -- the passed item is a single file, suitcase, clipping, etc.
-- check the label of the item. If it is the marked label, then it's already been processed so ignore.
tell application "Finder"
if (the label index of this_item) as integer is the special_label_index then
return "ignore"
end if
end tell
set the check_flag to false
repeat
tell application "Finder"
set the item_file_type to the file type of this_item
end tell
if the check_flag is true and ¬
the item_file_type does not start with "bzy" then
tell application "Finder"
set the label index of this_item to the special_label_index
end tell
-- allow the Finder time to change the label
«event sysodela» the item_check_delay_time
return false
else if the item_file_type does not start with "bzy" then
-- set the flag and check again
set the check_flag to true
end if
-- pause for the indicated time
«event sysodela» the item_check_delay_time
end repeat
end if
end check_busy_status
--HANDLER FOR KEEPING THIS FOLDER OPEN
--To activate the handler, remove the comment markers (the parens and asterisks) at the beginning and end of the following handler and save this script.
(*
on closing folder window for this_folder
beep
tell application "Finder"
open this_folder
end tell
end closing folder window for
*)