Populating a popup button dynamically

I have quite a problem with a popup button that I want to dynamically populate from a list of folders. After the app launches, I want it to get the list of folders in the mounted volume “staff”. Then I want to set the menu items of the popup button to that list. TeacherListBox is the name of the Popup button (I set it in IB) and Handin is also correct. The applescript won’t save (and make pretty syntax colors). The mounting works as well as the list. If I remove the “make new menu item…” line and put:


display dialog (item i of teacherList as string) 

it shows the folder names.

I keep getting the “Expected end of line but found identifier” after “popup button” on the following


on will finish launching theObject
-- mounting the volume here

tell application "Finder"
		set teacherList to get items in disk "staff"
		repeat with i from 1 to (count of teacherList)
			make new menu item at the end of menu items of menu of popup button "TeacherListBox" of window "Handin" with properties{ title: (item i of teacherList as string), enabled:true}
		end repeat
	end tell
on will finish launching

Thanks for any and all help.

Brian

(I’m using 10.4.1 but the target OS for this app will be 10.3.x)

The main problem is that you’re putting the commands for your app inside of a Finder tell block and the Finder doesn’t know what to do with them. Try this:

on will finish launching theObject
-- mounting the volume here

	tell application "Finder" to set teacherList to get name of items in disk "staff"
	tell menu of popup button "TeacherListBox" of window "Handin"
		repeat with i from 1 to (count of teacherList)
			make new menu item at the end of menu items with properties {title:item i of teacherList as unicode text}
		end repeat
	end
end will finish launching

Jon

Awesome :smiley: Thanks!

Brian