• 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: kai <email@hidden>
  • Date: Wed, 17 Jan 2007 00:41:57 +0000


On 16 Jan 2007, at 23:52, Adam Bell wrote:

I haven't followed this carefully, but given the naming convention rigidities, wouldn't this work:

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"}
-- with the assurance of only one "." and only "_M" preceding it to deal with:
set bname to {}
repeat with aName in names1
if aName contains "_M" then
set bname's end to aName's text 1 thru ((offset of "_M" in aName) - 1)
else
set bname's end to aName's text 1 thru ((offset of "." in aName) - 1)
end if
end repeat


Same answer, anyway.

Indeed, Adam.

If the list of names is likely to be a lengthy one, something like this might be worth considering, too:

-------------------

to strip_extensions from q to e
	script o
		property l : q
	end script
	set tid to text item delimiters
	set text item delimiters to "."
	considering case
		repeat with i from 1 to count o's l
			tell text item 1 of o's l's item i to if it ends with e then
				set o's l's item i to text 1 thru -3
			else
				set o's l's item i to it
			end if
		end repeat
	end considering
	set text item delimiters to tid
	o's l
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"}

set names1 to strip_extensions from names1 to "_M"

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

-------------------

---
kai


_______________________________________________ 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>
References: 
 >Re: Text items (From: "Fleisher, Ken" <email@hidden>)
 >Re: Text items (From: kai <email@hidden>)
 >Re: Text items (From: kai <email@hidden>)
 >Re: Text items (From: kai <email@hidden>)
 >Re: Text items (From: Adam Bell <email@hidden>)

  • Prev by Date: Re: weird behavior
  • Next by Date: Re: Javascript within and applescript
  • Previous by thread: Re: Text items
  • Next by thread: Re: Text items
  • Index(es):
    • Date
    • Thread