AppleScript Help - Need Simple Database

Discussion in 'Mac Programming' started by kkachurak, Aug 11, 2011.

  1. kkachurak macrumors regular

    Joined:
    Jun 26, 2007
    Location:
    Orlando, FL
    #1
    I am fairly new to AppleScript and have been primarily using Macscripters.net for examples. However, I am embarking on a project that, while somewhat simple on the outside, requires something a bit more complex on the inside.

    Here's what I what to accomplish:

    I'm writing a series of scripts that need to check to see the boolean status of a few different things. Using Insteon hardware and Indigo 4, I want a database to maintain the following things:

    Entertainment System is on {true or false}
    Patio door is open {true or false}
    Person #1 is home {true or false}
    Person #2 is home {true or false}

    *and if it's possible, though not immediately necessary in my first version, I'd like a log to keep track of the last 50 times the front door was opened. This wouldn't be a boolean status... it would be a series of time and date stamps.

    My instinct is that this data could be retained in a simple .rtf document and called upon using text delimiters each time when a script needs to decide what to do using a if / else statement. Though this seems like it might be archaic.

    As I said, I'm new at this, so I'm looking for pointers or examples if anyone could spare a moment. Thank you.
     
  2. creativecag macrumors newbie

    Joined:
    Aug 11, 2011
    #2
    I would use a sqlite database. I would have id's associated with your different 'states' (i.e. person 1 is home, ent center is on, etc) and then associate the time stamps to those ids and filter them. You can use 'do shell script' to run all sqlite3 queries thru the shell.
     
  3. kkachurak thread starter macrumors regular

    Joined:
    Jun 26, 2007
    Location:
    Orlando, FL
    #3
    Thank you. Just as soon as I figure out what sqlite and shell scripts are, I will look back on this as guidance ;)

    Seriously though, thanks.
     
  4. res1233, Aug 11, 2011
    Last edited: Aug 11, 2011

    res1233 macrumors 65816

    res1233

    Joined:
    Dec 8, 2008
    Location:
    Brooklyn, NY
    #4
    Applescript has decent XML and plist managing ability. You should be able to use XMLs and plists to store your data, and call it when needed. I have not used Applescript with XMLs much, but I know it's pretty capable.

    Another option is using properties. Not sure if you know about them or not, but you can use them to store variables persistently, till re-saving the script. For example:

    Code:
    property x : 0
    x will always equal zero now each time the script runs, however, if I do something like:

    Code:
    property x : 0
    set x to 5
    Now the x property's data changes to 5, and is saved to disk. Not sure if I'm being clear enough, but this is generally how I manage data I want to be persistent.

    So in your case you could type:

    Code:
    property EntertainmentSystemON : false
    Now if your code changes this to true, next time you run the script, it'll remember the value. The issue with properties is, like I said, it'll forget the values once you re-save the script, so if you want completely persistent data, use XMLs or plists. XMLs and plists also allow you to create entire databases, so that's probably what you're looking for. Plists are a kind of XML, so you should be fine with either.
     

Share This Page