• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Convert Case and Remove Space
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Convert Case and Remove Space


  • Subject: Convert Case and Remove Space
  • From: Steven Valenti <email@hidden>
  • Date: 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.


set ListOfFolderNames to {"MP298351-STAR SHIP 1905",
"MP298351-StarShip1905", "MP123456-JEEP", "MP298593-KJJonesCPA(la)"} --A
list of some example job names


set ChosenFolder to (choose from list ListOfFolderNames with prompt "Choose
folder") as string

set AppleScript's text item delimiters to " "

set FolderName to text items of ChosenFolder as list

set AppleScript's text item delimiters to {""}


global new_text


set FinalFolderName to ""

repeat with i in FolderName

        if (i as string) = (item 1 of FolderName) then

                set TextItem to i as string

                set TextItem to (items 10 thru (count of characters in
TextItem) in TextItem) as string

        else

                set TextItem to i as string

        end if

        change_case(TextItem)

        set FinalFolderName to FinalFolderName & new_text

end repeat


set FinalFolderName to items 1 thru 9 of (FolderName as string) &
FinalFolderName as string


on change_case(this_text)

        set the comparison_string to
"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-abcdefghijklmnopqrstuvwxyz"

        set the source_string to
"abcdefghijklmnopqrstuvwxyz1234567890-abcdefghijklmnopqrstuvwxyz"



        set the new_text to ""

        try

                set TextToConvert to (items 2 thru (count of characters in
this_text)) in this_text

        on error

                set new_text to this_text

                return new_text

        end try

        repeat with this_char in TextToConvert

                set x to the offset of this_char in the comparison_string

                set the new_text to (the new_text & character x of the
source_string) as string

        end repeat

        set new_text to item 1 of this_text & new_text

        return the new_text

end change_case


 _______________________________________________
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

  • Prev by Date: Re: Applescript-users Digest, Vol 1, Issue 122
  • Next by Date: Re: [OT] Mac CAD software
  • Previous by thread: Re: Applescript-users Digest, Vol 1, Issue 122
  • Next by thread: Re: Convert Case and Remove Space
  • Index(es):
    • Date
    • Thread