Make it brief... general AS tidbit

I see a lot of redundant code posted in these forums and while this may not be the most mind blowing concept in the world, it does help make your code a little shorter and more flexible.

When I have a series of things to generate I will usually create a property list with info for each iteration… Here’s a simple example…


property folderNames:{"Images","Fonts","Client Originals","¢Not For Use"}
tell app "Finder"
repeat with thisFolder in folderNames
set newFolder to make folder at desktop with properties {name:thisfolder}
end repeat
end tell

This seems like a simple concept but does allow for flexibility like adding or removing a folder from this list. Want to add a folder named “Jim’s Files”? Just tack it onto the list and away we go! (Also, it’s nice to have this list up at the top of the script so you don’t have to root around in the bowels of your script looking for values!)

Lately, I have been applying the same logic to XCode projects with data sources (I am writing things where I can be daily varying the amount of data I’m storing!) So I just throw it in a property up top and repeat to make the data columns / rows.


property dataColumnList:{"City,","State","Zipcode"}
-- Do a bunch of other AS stuff... Blah,blah,blah...
tell datasource
repeat with thisValue in dataColumnList
make new data column at end of data columns with properties {name:thisValue}
end repeat

Once again, if I want to add or remove data, it’s as easy as changing this property! No searching or cutting and pasting.

Simple but effective. I’m sure you can find many more ways to use this concept to streamline and give a little more flexibility to your script.

Have fun,
Jim Neumann
BLUEFROG