Dropdown menu

I need a dropdown menu that will let me/someone choose where to download something. When they select one of the choices, it’ll do shell script.
any hints?

The drop down menu would contain
Option A download form 1 site
option b download from 2 site.

Create a dropdown somewhere in your screen. I call it optionselector in this example.

on awake from nib theObject
	tell window 1
		set thePopupItems to {"OptionA", "OptionB"}
		tell menu of popup button "optionselector"
			delete every menu item
			repeat with aMenuItem in thePopupItems
				make new menu item at end of menu items with properties {title:aMenuItem}
			end repeat
		end tell
	end tell
end awake from nib


"On doing something"
set selected_option to title of current menu item of popup button "optionselector" of window 1

"if selected_option is OptionA/OptionB  => do shell script for optionA or OptionB"


on awake from nib theObject
	tell window 1
		set thePopupItems to {"Leopard", "Tiger"}
		tell menu of popup button 1
			delete every menu item
			repeat with aMenuItem in thePopupItems
				make new menu item at end of menu items with properties {title:aMenuItem}
			end repeat
		end tell
	end tell
end awake from nib


"On doing something"
set selected_option to title of current menu item of popup button "optionselector" of window 1

if thePopupItems is "Leopard" then
	do shell script ""
else
	display dialog ""
end if

Whats wrong with that for when the user selects Leoaprd?
And Is it possible to use this in a viewer? (Tabs viewer) i tried to change window 1 to view 1, but that didn’t do it…

"On doing something"
set Leopard to title of current menu item of popup button "Leopard" of window 1

if Leopard is selected then
	do shell script ""
else
	display dialog ""
end if

This is what i also tried.

Whats wrong with that for when the user selects Leoaprd?

This should be:


if selected_option is "Leopard" then
	do shell script ""
else
	display dialog ""
end if

Sure it is. Try:

set selected_option to title of current menu item of popup button "optionselector" of tab view item 1 of window 1
on awake from nib theObject
	tellwindow 1
		set thePopupItems to {"Leopard", "OptionB"}
		tell menu of popup button "optionselector"
			delete every menu item
			repeat with aMenuItem in thePopupItems
				make new menu item at end of menu items with properties {title:aMenuItem}
			end repeat
		end tell
	end tell
end awake from nib


"On doing something"
set selected_option to title of current menu item of popup button "optionselector" of window 1

if selected_option is "Leopard" then
	do shell script ""
else
	display dialog ""
end if

Doesn’t work, when i select Leopard, it doesn’t respond by displaying the dialog.
Also
set selected_option to title of current menu item of popup button “optionselector” of tab view item 2 of window 1

tried that but doesn’t work. so then i changed tellwindow 1 to tab view item 2 of window 1 both didn’t work.

What do you get if you use a display dialog like

set selected_option to title of current menu item of popup button "optionselector" of window 1
display dialog selected_option

You are right. It should be:

set selected_option to title of current menu item of popup button "optionselector" of tab view item 1 of tab view 1 of window 1

Note: “of tab view item 1” is off course the number of the tab you’re on.

sorry no responce. by the way, when we do figure this out it will be doing an do shell script command. but we can so display dialog for now :slight_smile: then I should be able to figure out how to change it. most likely it’d be easy

No response… bummer…

Did you “connect” your buttons to an applescript inside “Interface Builder”? You need to connect them via the “Inspector” Applescript option (menu: Tools → Inspector).

If you don’t get a response at all, instead of an error message, I think you did not connect them.

Correction, The applescript changes the Options of the popup window. IT just doesn’t display dialog. Yes i know how to link Applescript with items. :slight_smile:

Correction, The applescript changes the Options of the popup window. IT just doesn’t display dialog. Yes i know how to link Applescript with items. :slight_smile:

I dont mean to hijack guys, but rather starting a new thread for the same problem…

i ran into a similar problem, im in a similar situation, onlly i would like to make it so that when option A is selected, a string would = optionA, but if optionB is selected, then string = optionB,

However, obviously, im doing something wrong , as when i run my app, the code of the drop down box isnt changing the string, as i just get “error variable undefined”

i actually used this script, just replaced stuff a bit

fixing the error. as for string things I can’t help ya cause haven’t found a solution to my issue :frowning:
give me the code that your using exactly then I can help you for

Slacker, i believe me and you have the same problem, quite simply, nothings happening. Its not giving you the end result of displaying a dialog box, and its not changing the value of my string.

lol kind of why i jumped in here, i just read even closer.

I was just tyring to get mine to display in a dialog box, “you have chosen option A” (and then make it more complicated later) based on whats selected in the drop down. I even tried setting it as a menu, and adding my code inside of the code Xcode provides for you, one for each of the options, and no luck.

I’m new at applescript, i used to play with C++/VB, but everyone knows macs are better.

Guys,

I created a mini application. I zipped it and you can download it from my website. I will remove it after 31 december.

link: http://www.panorama.dyndns.org/tmp/dropdown.zip

HVDWolf,

THANK YOU!

This all makes sense now, i knew something had to be coded to make things happen when its selected, ie, the on action

One question though, what exactly is the point of the “delete every item”?

Hope slacker reads this soon, definitely helped me out.

Thanks bunch guys! I think i figured it out myself though :frowning: LOL o well i will try this :slight_smile: bet it’s better :smiley:

It’s more or less a safe-guard to initiate a “fresh” state of the object.

As an example: You might have a radio-button matrix that poulates a popup-button.
If radiobutton 1 is selected the popup is populated with: optionA, optionB, optionC
If radiobutton 2 is selected the popup is populated with: option1, option2, option3

If a user selects radiobutton 2 and then changes his/her mind and selects radiobutton 1, your popup would contain: option1, option2, option3, optionA, optionB, optionC.
That is where you would use the “delete every item” in between. In my case it is just “be safe and consistent all the time”.