• 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
Re: Text items
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Text items


  • Subject: Re: Text items
  • From: Adam Bell <email@hidden>
  • Date: Wed, 17 Jan 2007 10:07:28 -0400

Title: Re: Text items
I've taken the liberty of explaining Kai's clever script:

to strip_extensions from q to e -- q is the original list, e the occasional terminator
 
script o
               
property l : q -- casting a list as an embedded script property assures that the list object is kept in memory for rapid manipulation. Great speeder-upper for long lists.
     
end script
     
set c to -1 - (count e) -- minus ((number of characters in e) + 1), i.e. distance from end of name if e is there.
      
set tid to text item delimiters
set text item delimiters to "." -- find the period separating the extension.
   
considering case -- don't want opposite case of e
              
repeat with i from 1 to count o's l -- o's I is the original list in the embedded script object.
                       
tell text item 1 of o's l's item i to if it ends with e then
                            --
text item 1 of the list; the part before the extension's "." Is e in it?
                            
set o's l's item i to text 1 thru c --  Yes, so cut off c characters from the part of the name before the extension.
                   
else
                           
set o's l's item i to it -- no, so leave item i of the list minus its extension as is.
                 
end if
         
end repeat
     
end considering
set text item delimiters to tid
end strip_extensions

set names1 to {"231-001_M.tif", "231-001.tif", "231-001.jpg", "231-001-a_M.tif", "231-001-a.tif", "231-001-a.jpg"}

strip_extensions from names1 to "_M"

names1 --> {"231-001", "231-001", "231-001", "231-001-a", "231-001-a", "231-001-a"}

Wow. Thanks everyone for all the great suggestions. I certainly have plenty
to work with now.

I don't expect the lists to be longer than 100-200 files at any time, so
really any of these solutions is good--even my original loops aren't too
bad.

However, I think Kai's technique is certainly a more clever, efficient, and
general solution. I would really like to understand how it works, but I just
can't seem to follow the logic. Would someone like to give a line-by-line
explanation of how it does what it does? That would be very helpful for me.

Thanks again for the great ideas!

Ken

--
Ken Fleisher

Photographer
Imaging & Visual Services
National Gallery of Art
Washington, D.C.

Phone: (202) 712-7471
email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
>esscable.net
Archives: http://lists.apple.com/mailman//archives/applescript-users

This email sent to email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/mailman//archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Text items
      • From: kai <email@hidden>
  • Prev by Date: Re: Text items
  • Next by Date: Re: Splitting PDFs into single pages
  • Previous by thread: Re: Text items
  • Next by thread: Re: Text items
  • Index(es):
    • Date
    • Thread