To plist or not to plist, that is my question

Hey, I could have gone with “I REALLY gotta plist!” so count yourselves lucky. :frowning:

Anyhow, Now that I am more than 60% finished with my scripting project it occurs to me, does Mac have something analogous to the PCs registry and can I use it to store applescript values? After some research I found the plist and it SEEMS to be what I am after, but I can’t be sure.

Let’s say that I want to save the last date a maintenance script was run (which I do by the way). I am currently storing that date information in a text file and I have several text files storing just a tiny bit of data like the last archive folder name or the current queue order in case of a power outage (which happens here a lot, crappy grid!). Remembering what an inquisitive sort I was in the (recent) past I know for a fact that a user like myself will feel compelled to screw with the data in those text files just to see how it will affect the scripts. The problem is it will likely crash them. Not that I’ve ever done that. Just saying.

Are plists the better way to go? What are their limitations and strengths when used in applescript? Should I bother rewriting this far into my project?

Any help will be much appreciated.

Oh, and what are the chances that I will be able to retool my project for Applescript Studio once I am done? How much extra work will be required?

If you have something that works then I’m not sure there’s much advantage to changing it. I think plist files are easier to use because they have their own file structure and thus and you only have to use 2 commands to get data in/out of them (i.e. defaults read and defaults write). With text files you have to create your own data structure and make sure to follow that data structure throught your script. You say you have 40% more to go on your project, so if you will have the need to read/write more data then you may want to change to an easier format.

I’m going to give you another choice rather than plist files. There’s a new storage method in town, did you know? As of OSX 10.4 applescript supports saving data in a database. It’s called “database events” and since it’s new I would suspect that database events will become more important as time goes on… so it might be wise to learn about them. I’ve only used them a few times but they’re easy to use. For simple data storage needs I don’t think they’re any easier than plist files, but for complex storage needs they’re the best method. It’s difficult to create arrays of data with plist files but not with database events. In other words, text files and plist files are easy to use to store strings and sometimes even lists of data, but if you need to store things in a “record” format then database events are the way to go. I learned about them from this article. It should give you enough information to decide if you want to use them…

Ha! That’s a funny one. If you’ve never used applescript studio then you’re in for a surprise. Although people will tell you it’s a “simple” development environment, that’s only relative to other environments. It may be simpler but it’s still complicated. If your starting from ground zero with no development experience, like I did, then there’s much work involved in converting your script to an AS application. There’s terms and things that you’ve never heard before, so the learning curve is large. I’m not trying to dissuade you from experimenting with it, I’m just giving you a realistic expectation. It’s not like applescript where you can just jump in and start creating scripts, you will need some help getting started so find a book or some tutorials.

Good luck!

Thanks for the info regulus6633.

The link to the database events article anticipated one of the applescript tasks left in the 40% still undone. I am really dragging my feet on it since it has been years since I have had to design a relational database and have forgotten quite a bit, then to add applescript into the mix… bleh.

I kind of figured that Applescript Studio wasn’t going to be easy and that a book would no doubt be necessary but the warning is appreciated. Maybe I will start small and just create a small monitoring program to give the user a visual indication of how the scripts are progessing. And the funny part is I said that like it will be a cakewalk.

I guess it will be easier for now to move the text files into the library and put them in some inscrutibly named folder to keep the curious away. I can always go to the plist in the rewrite after it is up and running, and since I am doing this project for myself I am sure there will be plenty of those. I am already looking at code I wrote two months ago and seeing how I could make it better.

Again, thanks.

You could also use a property for the variable which will reset when the script is compiled but from then on it will save the value from the last time the script was run. You could also write your data to a text file and read it when needed.