Hi
I have been reading the posts below and have read that there is no way to import data from an Excel file with out opening the file. Is this the really the case. If so is there any way that i can import have just one file (such a text file) that has the abilty to be read as columns? Basicaly im creating an application which has 2 pop up windows. The first popup is easy to populate on its own but the second popup window i would like to populate it with varying content depending on what popup one is displaying. The reason for having it in one file is that this file might change, rather than changing multiple text files.
An Example of what im trying is below.
popup 1 popup2
CD Rom not ejecting
not reading
Hard Drive making a noise
not booting
You can save the excel data as tab delimited text which is easy to read with AppleScript. What you’re saying is that if popup 1 is set to “Hard Drive” you want popup 2 to contain:
making a noise
not booting
right? Also, how many menu items are there in your app?
Hi Kel
Thanks for the help. By Menu items i presume you mean contents of the popups. Popup munu 1 can contain up to 82 ubjects and Popup menu 2 can contain up to 15 objects
My plan is to have 2 Radio buttons, depending on which one is selected, display a list of items in popup 1 and then depending on what is selected in popup 1, popup 2 will display a relevent list to what is in popup 1. I hipe that makes sense.
After you save your file as tab delimited and read it in, you can split it up like this:
set t to "CD Rom not ejecting
not reading
Hard Drive making a noise
not booting"
-- create lookup list and list of data
set p_list to paragraphs of t
set popup1 to {}
set popup2 to {}
set c to 0
repeat with this_p in p_list
set {item1, item2} to StringToList(this_p, tab)
if item1 is not "" then
set c to c + 1
set end of popup1 to item1
set end of popup2 to {item2}
else
set end of item c of popup2 to item2
end if
end repeat
{popup1, popup2}
-- returns list from string with delimiter
on StringToList(s, d)
set utid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {d}
set l to text items of s
set AppleScript's text item delimiters to utid
return l
end StringToList
What you end up with is two lists; popup1 and popup2. popup1 is a list of your menu items for popup1. popup2 is a list of lists where the sub lists are menu items for popup2 depending on which set is selected in popup1. You access the sublists by index. There are several ways to get the index, but for less than 100 items, a repeat loop should do ok. If not make a post for quicker ways to do this.
set popup1_value to “somevalue”
set c to count popup1
repeat with i from 1 to c
if item i of popup1 is popup1_value then exit repeat
end repeat
i
Here i is your index and you can get the set of menu items from popup2 with:
Hi Kel
Thanks for all your help, it is very much appreciated.
However im still having problems with the script in the previous post. In AppleScript editor it comes back with "cant get item 2 of {“CD Rom not ejecting”}
any ideas?
I now have 2 text files (I have saved my Excel file as a Text (tab delimited)) called Hardware.txt and Software.txt.
I have the following script which will enable my app to use the Radio buttons to select Radio1 or Radio 2.
property textFilePaths : {"/Users/test/Desktop/Hardware.txt", "/Users/test/Desktop/Software.txt"}
property pulldownTitles : {"Hardware", "Software"}
on clicked theObject -- handler connected to the Radio Button matrix
--if name of theObject is "CallSubject1" then
set selectedFilePath to quoted form of (item (current row of theObject) of textFilePaths)
set selectedTitle to (item (current row of theObject) of pulldownTitles)
set menuItems to {selectedTitle} & (paragraphs of (do shell script "cat " & selectedFilePath & " | sort -f"))
tell popup button "CallSubject2" of window "Window"
call method "removeAllItems" of it
call method "addItemsWithTitles:" of it with parameter menuItems
end tell
--end if
end clicked
Depending on which is selected Radio1 or Radio 2, Radio1 will sourse Hardware and Radio2 will sourse Software.
Popup button 1 will select a single cell from the text file eg. CDRom
and
Popup button 2 will select all subsequent cells in the same row as popup button 1 eg. Not Ejecting, Not Reading etc…
I know im asking alot but if you or any one else can help please let me know