On Sep 25, 2009, at 8:07 AM, Jim Brandt wrote: I have a script that I use to manipulate the names of the files within a folder. I want the names to be word capitalized, all underscores changed to spaces, and optionally, based on an input response, the first word of the name uppercased.
Anything you can do with plain text in a text editor, you can do much faster in AppleScript. For example ...
(* id of "a" -- 97 id of "z" -- 122 id of "A" -- 65 id of "Z" -- 90 *)
set firstWord to "xnchdgrtsjdlvmfqq12345" set charList to characters of firstWord repeat with i from 1 to (count items of charList) set charID to id of (item i of charList) if (96 < charID) and (charID < 123) then set charID to (charID - 32) set item i of charList to (character id charID) end if end repeat set firstWord to charList as text
converts text to upper case.
Use 'AppleScript's text item delimiters' whenever possible. For example, something like this ...
set AppleScript's text item delimiters to {"_"} -- get a list of text chunks separated by "_" set AppleScript's text item delimiters to {space} -- convert the list of chunks to text separated by " "
will convert underscores to spaces. |