Can an applescript "make" it's own variables? Or do I have to manually make "blanks"

Discussion in 'Mac Programming' started by Corrado33, Sep 1, 2009.

  1. Corrado33 macrumors member

    Joined:
    Sep 2, 2008
    #1
    So I'm writing a program that periodically adds things to a list. That's the easy part. However, each item in the list has it's own separate list associated with it. So let's say my script adds something to the first list, that would mean it would need to create the corresponding list that goes along with that entry, but I don't know how to make applescript make it's own variables. I'll make a diagram to try to explain this.

    Initial List. . . .Sub_lists
    . . .|. .. . . . .Entry1-1
    . . \|/ . . . . Entry1-2
    Entry1--------Entry1-3

    . . . . . . Entry2-1
    Entry2-- Entry2-2
    . . . . . . Entry2-3

    Entry3---Entry3-1
    . . . . . .\Entry3-2
    . . . . . . Entry3-3

    So if I make Entry4, I would need the program to make the sublist that includes Entry4-1, Entry4-2, and Entry4-3.
    Then, if I make Entry5, again I would need the corresponding sublist, but with a different name (so I can save all of the sublists separately)

    Hmm, I just thought maybe I could use files, and output the stored lists into a text file.... I'll try that too.

    Anybody have a way I could just make variables like I was saying? Thanks!
     
  2. mysterytramp macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #2
    Honestly, I'm a little vague on what you're trying to do, but maybe this will help.

    Code:
    set masterList to {}
    
    set dummyList to {1, 2, 3}
    
    set masterList to masterList & dummyList
    
    set dummyList to {4, 5, 6}
    
    set masterList to masterList & dummyList
    
    set dummyList to {7, 8, 9}
    
    set masterList to masterList & dummyList
    masterList is {1, 2, 3, 4, 5, 6, 7, 8, 9}

    Code:
    set masterList to {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
    
    set dummyList to {1, 2, 3}
    
    set item 1 of masterList to dummyList
    
    set dummyList to {4, 5, 6}
    
    set item 2 of masterList to dummyList
    
    set dummyList to {7, 8, 9}
    
    set item 3 of masterList to dummyList
    masterList is {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, 0, 0, 0, 0, 0, 0, 0}

    Does this help?

    mt
     
  3. mysterytramp macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #3
    Alternatively, you should have an application called "Database Events" on your Mac. (Check /System/Library/CoreServices) It is a scriptable, faceless app, where you can create fields, and create and delete records. Here's an intro.

    You should see a speed advantage with Database Events over reading/writing to a text file.

    mt
     
  4. Corrado33 thread starter macrumors member

    Joined:
    Sep 2, 2008
    #4
    Both of you are ingenious. :) Thank you so much, that's exactly what I need to do.
     
  5. mysterytramp macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #5
    I thank you. And I thank you, too.

    (Now would be a good time to work in an "I and I" reference, but I'm not sure anyone would know what I'm talking about.)

    mt
     

Share This Page