I am new to AppleScript Studio, and am having trouble with reading text fields and switches from the user interface. I’m building my first app (mainly as a learning experience), which will batch process a bunch of pictures. The interface has 11 switches, 5 of which are in a group; and 22 text fields, 15 are in an array of 3x5 fields. Is there a way to group some of the switches and text fields so that they can be read within a repeat loop. Right now I have a long list of:
set amount64 to contents of text field "amount64"
It all works, but I’m looking for a better way. It is very slow… It takes about 2 seconds to finish reading the text fields and switches into the variables. Is it slow because of my technique? or is that just the way it is. Does it matter that these variables are properties (I plan to save them as defaults) and I am moving from an “on clicked” handler to another handler?
Any help to make me a better Applescripter would be appreciated.
Thanks
Scott
You might want to consider whether or not Tables might be of use for your application. Displaying a table may be one way to consolidate all those text boxes, and to allow as many items as the user wants, not some arbitrary limit. You can use drag and drop to enter the filenames, if you like.
A cell (or cells) in the table could also be used for storing results. Check out “Table Sort” and “Drag and Drop” in /Developer/Examples/AppleScript Studio/ for some ideas.
To use tables, you need to create a data source. Here’s one way to go about that:
on awake from nib theObject
if the name of theObject is "SourceList" then
createDataSource("SourceList", {name:"TheFile"}, {"file names"}, theObject)
end if
end awake from nib
on createDataSource(dataSrcName, dataColumnsProps, dragTypes, theObject)
(* Create the data source for the table view *)
set theDataSource to make new data source at end of data sources with properties {name:dataSrcName}
(* Create the table's data columns *)
make new data column at end of data columns of theDataSource with properties (dataColumnsProps as record)
set data source of theObject to theDataSource -- Assign data source to table view object
tell theObject to register drag types (dragTypes as list) -- accept only this type of item
return theDataSource
end createDataSource
Note: There should be a loop on data columns; the code above assumes only a single column.
And to read data from a table, something like:
repeat with theItem in (contents of data cell "TheFile" of data rows of data source "SourceList") as list
Hope this helps.