• 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: Tue, 16 Jan 2007 19:50:21 +0000


On 16 Jan 2007, at 18:12, Fleisher, Ken wrote:

I have the following code:

    set AppleScript's text item delimiters to "."
    repeat with i from 1 to c1
       set item i of names1 to text item 1 of item i of names1
   end repeat

This will for example take the file name without the “.xxx” extension for every file name in a list (I know there can be “.” elsewhere in the name, but for this purpose, our naming conventions do not permit it.)

Is there some way to do this without the loop? For example, this does not work:

set AppleScript's text item delimiters to "."
set names1 to text item 1 of every item of names1

While the following routine still uses a repeat loop, it will repeat only as many times as there are different name extensions - regardless of how many filenames are actually involved. (The test list, for example, will cause the handler to loop 3 times - once for each extension: "psd", "jpg" and "tif".) It is intended only for use on filenames with a single "." (as is the case with your naming conventions).


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

to strip_extensions from l
	set tid to text item delimiters
	set text item delimiters to return
	set l to l as Unicode text
	repeat
		set text item delimiters to "."
		if (count l's text items) is 1 then exit repeat
		set text item delimiters to "." & ¬
			paragraph 1 of l's text item -1
		set l to l's text items
		set text item delimiters to ""
		set l to l as Unicode text
	end repeat
	set text item delimiters to tid
	l's paragraphs
end strip_extensions

set names1 to {"pic 1.psd", "pic 2.jpg", "pic 3.psd", ¬
	"pic 4.jpg", "pic 5.tif", "pic 6.psd", "pic 7.psd", ¬
	"pic 8.tif", "pic 9.jpg", "pic 10.psd"}

set names1 to strip_extensions from names1

--> {"pic 1", "pic 2", "pic 3", "pic 4", "pic 5", "pic 6", "pic 7", "pic 8", "pic 9", "pic 10"}

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

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

  • Prev by Date: Re: Text items
  • Next by Date: Re: Return Delimiter
  • Previous by thread: Re: Text items
  • Next by thread: Re: Text items
  • Index(es):
    • Date
    • Thread