• 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: Adam Bell <email@hidden>
  • Date: Thu, 29 Dec 2005 16:57:38 -0400

On 12/29/05, kai <email@hidden> wrote:
>
> 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
>

But surely the "normal" way to do it would be to bite the list up
(after being sure that the insertion was interior to the list (not
done here):

set myList to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"}
set listInsert to ASCII character 240 -- an apple
set insertAfterPosition to 7

insertInList(myList, listInsert, insertAfterPosition)

to insertInList(myList, listInsert, insertAfterPosition)
	tell myList
		set frontPart to items 1 thru insertAfterPosition
		set backPart to items (insertAfterPosition + 1) thru -1
	end tell
	set myList to frontPart & listInsert & backPart
end insertInList

--
Some minds remain open long enough for a truth to both enter and leave
without processing.
 _______________________________________________
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: kai <email@hidden>
References: 
 >Re: Arrays in AppleScript ? (From: Paul Berkowitz <email@hidden>)
 >Re: Arrays in AppleScript ? (From: kai <email@hidden>)

  • Prev by Date: Re: Arrays in AppleScript ?
  • Next by Date: How to choose a folder for desktop image
  • Previous by thread: Re: Arrays in AppleScript ?
  • Next by thread: Re: Arrays in AppleScript ?
  • Index(es):
    • Date
    • Thread