Ok, I’ve got several things I need help on so this is going to be a long post.
I’m working on a AppleScript Studio application and for the last day or so I’ve been searching learning and doing more and more but I’ve finally hit a wall and need help. Not just with the AppleScript side but maybe there are better easier way to do some things I’m trying to do.
This application basically is going to read data from a text file, builds a pop up menu with that data and when an item of the menu is selected it will place the data into two text fields. With my days worth of work I’ve managed to make a text file formatted like below and get the name into a variable called ShipType and the two numbers into variables into ShipCrew and ShipS with this code:
try set dataFile to (open for access file path:to:file with write permission) end try try set theText to items of (read dataFile using delimiter ",") end try try set CountNum to (count of theText) on error beep end try close access dataFile try set ShipType to the first item of theText set ShipCrew to the second item of theText as number set ShipS to the last item of theText as number end try
Text file (Note that the Thing 1 place might be a multiword name):
First off if there is an easier way to do what I did above I would be glad to hear it. So I’m stuck in two places. First I’ve only figured out how to read from one line. I would like to hit return and put in another line for the next thing and so on with no hard coded limit for the number of items to import. I can’t think of anyway to do this yet. Again I’m not set on this particular way of formating the file, if doing it a different way would be easier I’m all for it.
Example of file I want to import:
Thing 1,200,500 Thing2,2,1 Thing3,678,325 Thing 4,56,64
Second I want to populate a pop up button list with the data from the file. Specifically I want the names to be listed and when the user selects one of the items in the list it will put the two numbers into separate text fields. Currently my pop up button is named Menu1 and the first number need to go into a text field named PlayerC and the second number to PlayerS. Currently my menu code is set up like this:
on choose menu item theObject tell window of theObject set PlayerStrength to title of current menu item of popup button ï¿½ "Menu1" if PlayerStrength is "Thing 1" then set the contents of text field "PlayerS" to 2 set the contents of the text field "PlayerC" to 1
The program then goes on the reference those text fields and does math with the numbers but I’m pretty sure that doesn’t need changing. So, I know that a lot of questions but any help would be appreciated, thanks.