• 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
how to create a reference a variable at runtime
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

how to create a reference a variable at runtime


  • Subject: how to create a reference a variable at runtime
  • From: 2551phil <email@hidden>
  • Date: Sun, 05 Mar 2017 12:41:26 +0700

I’m not sure if my subject line is the correct way to describe the problem, but I have a bunch of lists at the top-level of my script, lets call them

List1
List2
List3
…
…

In my code, I want to target the output of some test to the correct list. The correct list will be ‘List’ + the index number of the variable i in a repeat loop.

What I want to do is something like

		if someText contains this_test then
			set targetList to “List” & i as text
			set end of my (targeList) to someText

But this doesn’t work, of course, because targetList contains a string, rather than points to my List.

At the moment, I have something like this:

	repeat with i from 1 to count of testStuff
		set this_test to item i of testStuff as text
		if someText contains this_test then
			if i is 1 then set end of List1 to someText
			if i is 2 then set end of List2 to someText
			if i is 3 then set end of List3 to someText
			…
			...
		end if
	end repeat

This works, but requires a separate statement for the count of testStuff, and given my count is going to be quite high, this is going to be tedious, ugly and expensive.

How do I create a variable at runtime that points to another variable in my script?


Best


Phil





 _______________________________________________
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/archives/applescript-users

This email sent to email@hidden


  • Follow-Ups:
    • Re: how to create a reference a variable at runtime
      • From: Shane Stanley <email@hidden>
  • Prev by Date: Re: Conversion of ISO Date String to AppleScript Date
  • Next by Date: Re: Conversion of ISO Date String to AppleScript Date
  • Previous by thread: Re: Conversion of ISO Date String to AppleScript Date
  • Next by thread: Re: how to create a reference a variable at runtime
  • Index(es):
    • Date
    • Thread