Radio Buttons and Text files.

Hi
Im trying to create an App that will use Radio Buttons. Initialy I would like to have 2 Radio buttons, 1 for Hardware and the second for Software. Depending on which is selected I would like it to pull information form respective text files and dispaly them in a pop down. I have been racking my brains and have not been able to find a solution. Is there a posible solution. The code i have is as follows


on awake from nib theObject
end awake from nib
on action theObject
	if current row of matrix "CallSubject1" of window "Window" is 1 then
		set dialogType to "Hardware"
	else if current row of matrix "CallSubject1" of window "Window" is 2 then
		set dialogType to "Software"
	end if
	if (name of theObject is "CallSubject1") then
		if dialogType is equal to "Hardware" then
			set AppleScript's text item delimiters to return
			set theList1 to do shell script "cat /Textfilelocation1.txt | sort -f"
			set pickList1 to text items of theList1
			delete every menu item of menu of popup button "CallSubject2" of window "Window"
			repeat with i in pickList1
				make new menu item at the end of every menu item of menu of popup button "CallSubject2" of window "Window" with properties {title:i, enabled:true}
			end repeat
			set title of popup button "CallSubject2" of window "Window" to "*Choose a Fault*"
		else if dialogType is equal to "Software" then
			set AppleScript's text item delimiters to return
			set theList2 to do shell script "cat /Textfilelocation1.txt | sort -f"
			set pickList2 to text items of theList2
			delete every menu item of menu of popup button "CallSubject2" of window "Window"
			repeat with i in pickList2
				make new menu item at the end of every menu item of menu of popup button "CallSubject2" of window "Window" with properties {title:i, enabled:true}
			end repeat
			set title of popup button "CallSubject2" of window "Window" to "*Choose a Fault*"
		end if
	end if
end action

any help would be great

Thanks in advance

Hi Major MD,

since you set a title for your popup button, I guess it’s a ‘PullDown’ type button?

If so - here’s my idea how to set & reset the menu of this button - using two methods of NSPopupButton with ‘call method’ is much more convenient than trying to solve this with AppleScript:

property textFilePaths : {"the/path/to/file1.txt", "the/path/to/file2.txt"}
property pulldownTitles : {"title 1", "title 2"}

on clicked theObject -- handler connected to the Radio Button matrix
	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 "popup" of window "main"
		call method "removeAllItems" of it
		call method "addItemsWithTitles:" of it with parameter menuItems
	end tell
end clicked

D.

Hi Dominik
Thanks for that. I have tried it our and all seems to work well. One Question, With interface builder, the default for Radio buttons is 2 one above the other. If i change the layout to have them next to each other the script does not work. Any ideas?

Many thanks
MD

Hi MD,

an NSMatrix is organized in columns & rows. So when you have two buttons in the same row, but in different columns, all you have to do is changing ‘current row’ in ‘current column’ in the script. Then it should work as expected. :slight_smile:

D.

Hi Dominik
Thanks for that, I managed to work it out after i replied to you. but thanks for all the help.
MD