• 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: Arrays in AppleScript ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Arrays in AppleScript ?


  • Subject: Re: Arrays in AppleScript ?
  • From: kai <email@hidden>
  • Date: Thu, 29 Dec 2005 20:35:56 +0000


On 29 Dec 2005, at 18:55, Paul Berkowitz wrote:

set mylist to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"}

set listInsert to "x"
set insertAfterPosition to 7

set mylist to my InsertInList(mylist, listInsert, insertAfterPosition)
--> {"a", "b", "c", "d", "e", "f", "g", "x", "h", "i", "j"}

on InsertInList(theList, listInsert, insertAfterPosition)
set end of theList to "dummy"
set listcount to count theList
repeat (listcount - insertAfterPosition - 1) times
set item listcount of theList to item (listcount - 1) of theList
set listcount to listcount - 1
end repeat
set item (insertAfterPosition + 1) of theList to listInsert
return theList
end InsertInList

I suppose this is all a bit tongue-in-cheek, but you could also traverse the list from the other end:


set mylist to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"}

set listinsert to "x"
set insertAfterPosition to 7

InsertInList(mylist, listinsert, insertAfterPosition)
mylist
--> {"a", "b", "c", "d", "e", "f", "g", "x", "h", "i", "j"}

on InsertInList(theList, listinsert, insertAfterPosition)
set beginning of theList to beginning of theList
repeat with currPosition from 2 to (insertAfterPosition)
set item (currPosition) of theList to item (currPosition + 1) of theList
end repeat
set item (insertAfterPosition + 1) of theList to listinsert
end InsertInList


---
kai


_______________________________________________ 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
  • Follow-Ups:
    • Re: Arrays in AppleScript ?
      • From: Adam Bell <email@hidden>
References: 
 >Re: Arrays in AppleScript ? (From: Paul Berkowitz <email@hidden>)

  • Prev by Date: Opening Finder windows in a dual monitor setup
  • Next by Date: Re: Arrays in AppleScript ?
  • Previous by thread: Re: Arrays in AppleScript ?
  • Next by thread: Re: Arrays in AppleScript ?
  • Index(es):
    • Date
    • Thread