Economy-x-Talk - Sample Scripts
Change Name Folder Action
This folder action changes the name of a file that is added to a folder by putting a number after the last but 4th character of the nae of the file.
The script comes from Scott Griffitts wo complained that he got stuck in an infinite loop. Testing this script in MacOS 9 did not cause an infinite loop.
on adding folder items to this_folder after receiving these_items
tell application "Finder"
repeat with eachfile in (these_items)
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ","
set k to text items of (name of this_folder as string)
set AppleScript's text item delimiters to ""
set newfile to k as text
set AppleScript's text item delimiters to " "
set k to text items of newfile
set AppleScript's text item delimiters to "_"
set newfile to k as text
set AppleScript's text item delimiters to tid
global numc
set numc to 0
set oldname to (name of eachfile) as string
set oldnamecount to length of oldname
try
repeat
set numc to (numc + 1)
if (numc is less than 10) then
set numtest to "_00" & numc
else if (numc is less than 100) then
set numtest to "_0" & numc
else
set numtest to "_" & numc
end if
set frontend to (newfile & numtest) as string
set backend to (characters (oldnamecount - 3) thru oldnamecount of oldname)
set bke to ""
repeat with ltr in backend
if (ltr is not ",") then
set bke to (bke & ltr) as string
end if
end repeat
set backend to bke
set newfilename to (((this_folder as string) & frontend as string) & backend as string)
if not (file newfilename exists) then
exit repeat
end if
end repeat
on error em
display dialog em
end try
display dialog (newfilename as string)
set name of eachfile to ((frontend as string) & (backend as string))
end repeat
end tell
end adding folder items to
Keep this extensive resource of tutorials and samples on-line! Support RunRev.info!
| Yes, this script is useful. I make a donation and choose freely how much I want to donate on-line (PayPal). Click here if you want to make a donation in dollars. | This script has not (completely) solved my problem and I want Economy-x-Talk to take care of it. Let me contact you. |
Copyright©2002-2008 by Mark Schonewille, Nijmegen, the Netherlands. This web site is in no way affiliated with Runtime Revolution Ltd., but we do recommend the Revolution development platform.