• 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: Creating variables with names from other variable values ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating variables with names from other variable values ?


  • Subject: Re: Creating variables with names from other variable values ?
  • From: has <email@hidden>
  • Date: Sat, 19 Mar 2005 16:29:57 +0000

cedrik wrote:

Seems i have a problem with variable names.
I have to create new variables with names from the VALUES of other variables.
E.g. I have:
set myVar to "width"
set myValue to 80

Now i wanna have the variable "width" with a value of "80".

AppleScript doesn't support introspection (the ability for scripts to explore and modify their own structure), so it can't be done. That said, introspection is hardly ever a necessary or appropriate solution, so this is not a big deal. (It's not the sort of feature you'd expect to find in a non-programmer oriented language anyhow.)


What you probably want is some kind of associative list or dictionary structure that allows you to store values by key. Unfortunately, AppleScript doesn't have a native dictionary type so you'll need to roll your own or use a third-party alternative. e.g. The AppleMods Type library <http://applemods.sourceforge.net/mods/Data/Types.php > provides both associative list and dictionary objects; example:

-- (library loading code omitted for clarity)

set dict to _Types's makeDict()
dict's setItem("width", 80)
dict's getItem("width")
--> 80


If you've not used AppleMods' libraries before, you'll need to download and install AppleMods' Loader system first <http://applemods.sourceforge.net/getstarted.html>. Run the Loader installer, then download and add the Types library to the ASLibraries folder. You can use the LoaderWizard applet to generate the library loading code to paste at the top of your script.


HTH

has
--
http://freespace.virgin.net/hamish.sanderson/
_______________________________________________
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:
    • FW: Creating variables with names from other variable values ?
      • From: cedrik <email@hidden>
  • Prev by Date: Cant get item x in LIST
  • Next by Date: Re: Setting all subfolder views to list
  • Previous by thread: Re: Creating variables with names from other variable values ?
  • Next by thread: FW: Creating variables with names from other variable values ?
  • Index(es):
    • Date
    • Thread