• 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
Lists and Variables
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Lists and Variables


  • Subject: Lists and Variables
  • From: "Larry Staton Jr." <email@hidden>
  • Date: Fri, 16 May 2003 11:20:48 -0400

How does one go about assigning variables to a list of variable length?

I have a variable length list of 1 to 10 strings. Each item of the list must be assigned to a variable named "TitleX", where X is item X of the list.

Here's what I want to do in code:

set tNames to {"bob", "sally", "alice", "timmy"}

repeat with i from 1 to (count items in tNames)
set Titlei to item i of tNames
end repeat

Result:
Title1 --> "bob"
Title2 --> "sally"
Title3 --> "alice"
Title4 --> "timmy"

TitleX --> item X of tNames

Unsurprisingly, the above does not compile.

What I have hacked up is 10 "if" statements like this:

if (count of tNames = 3) then
set {Title1, Title2, Title3} to tNames
end if

if (count of tNames = 4) then
set {Title1, Title2, Title3, Title4} to tNames
end if

if (count of tNames = X) then
set {Title1 . . . TitleX} to tNames
end if

return Title1
-- Result: "bob"

Is there a more efficient way to create dynamic variables from a list of unknown length?

TIA.

--
Larry Staton Jr.
E-mail/iChat: email@hidden
AIM: lstatonjr
http://www.statonlaw.net/weblog/

Brought to you by Mail on Mac OS X
Public PGP Key available upon request
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Lists and Variables
      • From: Deivy Petrescu <email@hidden>
  • Prev by Date: Re: Finding Remote Machine's IP
  • Next by Date: Re: Run-Only script in OSX 10.2.6
  • Previous by thread: Automate opening of filemaker database (server side)
  • Next by thread: Re: Lists and Variables
  • Index(es):
    • Date
    • Thread