Re: Convert Case and Remove Space
Re: Convert Case and Remove Space
- Subject: Re: Convert Case and Remove Space
- From: Nigel Garvey <email@hidden>
- Date: Tue, 19 Oct 2004 22:09:13 +0100
Steven Valenti wrote on Mon, 18 Oct 2004 14:23:54 -0400:
>
>The following script I have been building is suppose to correct any folder
>name that doesn't follow our naming convention. I put some examples in a
>list. The correct way for naming would be MP + Job Number + dash followed by
>name in upper and lower case with no spaces or special punctuation.
>(MP298351-StarShip1905). The first item in the list performs correctly but
>if it was correct to begin with, as in item 2 of list, it will set it in
>lower case (MP298351-Starship1905). Third Item in list is similar but gets
>set correctly. Last item errors because special punctuation was used. Would
>anyone have a better approach? Basically what I'm trying to achieve is:
>
>1. If it is all uppercase with spaces, set to upper and lower without spaces
>
>
>2. If it is upper and lower without spaces, leave it alone.
>
>3. If it contains special punctuation, remove it.
If you're allowed to install third-party OSAXen on your office machines,
the Satimage OSAX has 'uppercase' and 'lowercase' commands that would
help here.
I assume from your own code that the characters up to and including the
dash will always be OK and I'm guessing that you want capitalisation
after removed spaces but not after removed punctuation:
on standardiseFolderName(currentName)
set OKChars to
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
set part1 to text 1 thru 9 of currentName
set part2 to text 10 thru -1 of currentName
considering case
set allCaps to (part2 = (uppercase part2))
set nextCap to true
set part2 to part2's characters
repeat with i from 1 to (count part2)
set thisChar to item i of part2
if (thisChar is in OKChars) then
if nextCap then
set item i of part2 to (uppercase thisChar)
set nextCap to false
else if allCaps then
set item i of part2 to (lowercase thisChar)
end if
else if (thisChar is space) then
set item i of part2 to ""
set nextCap to true
else
set item i of part2 to ""
end if
end repeat
end considering
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ""
set newName to part1 & part2
set AppleScript's text item delimiters to astid
return newName
end standardiseFolderName
set ListOfFolderNames to {"MP298351-STAR SHIP 1905",
"MP298351-StarShip1905", "MP123456-JEEP", "MP298593-KJJonesCPA(la)"} --A
list of some example job names
set theChoice to (choose from list ListOfFolderNames with prompt
"Choose folder")
if theChoice is not false then
set newName to standardiseFolderName(item 1 of theChoice)
display dialog newName
end if
NG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden