I have a script that work just fine…
It flushes out illegal characters in a filename, as well as count the characters and alert the user if the count is over a script defined amount
I was wondering if anyone knows of a quick way to make this script ignore the extension of the file, because I would like to include a period as one of the illegal characters that the script will flush out, but because the files have .pdf, .qxd, .eps etc
Also, is there any way to make this script even faster, maybe through some other search and replace method…just wondering what other solutions there are for this same problem
here’s the script I have, it’s a droplet
on open (listFiles)
--Call To Check Name Length For Max Allowed, And If Too Long Ask User To Rename--
tell application "Finder"
my setName(listFiles)
end tell
--Clean Any Illegal Characters Out Of Name--
tell application "Finder"
repeat with i from 1 to count of listFiles
set elem to (item i of listFiles) as string
set fileItem to alias elem
set strName to name of fileItem
set replace_strings to ¬
{" ", " ", "-", "_", "__", "~", "`", ":", ";", "!", "@", "â„¢", "'", "®", "#", "$", "?", "<", ">", "%", "^", "&", ¬
"*", "(", ")", "=", "+", "{", "}", "[", "]", "|", "\\", "/", "'", ",", "\""}
repeat with this_replace_string in replace_strings
set strName to my FixName(strName, (contents of this_replace_string))
end repeat
set name of fileItem to strName
end repeat
end tell
end open
on FixName(currentName, fixString)
set AppleScript's text item delimiters to fixString
set listName to every text item of currentName
set AppleScript's text item delimiters to "_"
return (listName as string)
end FixName
--Direct Controller for Name Length--
on setName(fileList)
tell application "Finder"
repeat with thisItem in fileList
set item_name to name of thisItem
set item_container to container of thisItem as string
if kind of thisItem is not "Folder" then
set name_length to count item_name
if name_length > 22 then
set the_error to "This file's name has too many characters. It has " & name_length & " characters, but the limit is " & 22 & " total. "
repeat
set item_name to text returned of (display dialog the_error & "Please enter a new name:" buttons {"Proceed"} default button 1 default answer item_name)
set the_error to ""
try
get (item_container & item_name) as alias
set the_error to "A file with the name \"" & item_name & "\" already exists. "
end try
if the_error = "" then exit repeat
end repeat
set name of thisItem to item_name
end if
end if
end repeat
end tell
end setName