Tuesday, July 22, 2014

#1 2008-10-22 04:21:22 pm

slacker
Member
Registered: 2006-04-22
Posts: 126
Website

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?

Offline

 

#2 2008-12-06 03:34:37 pm

slacker
Member
Registered: 2006-04-22
Posts: 126
Website

Re: Dropdown menu

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

Offline

 

#3 2008-12-07 05:52:57 am

hvdwolf
Member
Registered: 2008-09-10
Posts: 60

Re: Dropdown menu

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

Applescript:

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"

Last edited by hvdwolf (2008-12-07 05:58:31 am)

Offline

 

#4 2008-12-07 09:52:55 am

slacker
Member
Registered: 2006-04-22
Posts: 126
Website

Re: Dropdown menu

Applescript:

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.....

Offline

 

#5 2008-12-07 10:01:43 am

slacker
Member
Registered: 2006-04-22
Posts: 126
Website

Re: Dropdown menu

Applescript:

"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.

Offline

 

#6 2008-12-07 10:02:29 am

hvdwolf
Member
Registered: 2008-09-10
Posts: 60

Re: Dropdown menu

Whats wrong with that for when the user selects Leoaprd?

slacker wrote:

Applescript:


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

This should be:

Applescript:


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

slacker wrote:

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.....

Sure it is. Try:

Applescript:

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

Last edited by hvdwolf (2008-12-07 10:03:24 am)

Offline

 

#7 2008-12-07 10:16:18 am

slacker
Member
Registered: 2006-04-22
Posts: 126
Website

Re: Dropdown menu

Applescript:

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.

Offline

 

#8 2008-12-07 11:28:38 am

hvdwolf
Member
Registered: 2008-09-10
Posts: 60

Re: Dropdown menu

slacker wrote:

Applescript:


"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

What do you get if you use a display dialog like

Applescript:

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

slacker wrote:

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.

You are right. It should be:

Applescript:

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.

Offline

 

#9 2008-12-07 12:30:03 pm

slacker
Member
Registered: 2006-04-22
Posts: 126
Website

Re: Dropdown menu

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 smile then I should be able to figure out how to change it. most likely it'd be easy

Offline

 

#10 2008-12-07 12:44:04 pm

slacker
Member
Registered: 2006-04-22
Posts: 126
Website

Re: Dropdown menu

No response..... bummer....

Offline

 

#11 2008-12-07 01:52:03 pm

hvdwolf
Member
Registered: 2008-09-10
Posts: 60

Re: Dropdown menu

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.

Offline

 

#12 2008-12-07 08:02:52 pm

slacker
Member
Registered: 2006-04-22
Posts: 126
Website

Re: Dropdown menu

hvdwolf wrote:

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.  smile

Offline

 

#13 2008-12-07 08:06:04 pm

slacker
Member
Registered: 2006-04-22
Posts: 126
Website

Re: Dropdown menu

hvdwolf wrote:

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.  smile

Offline

 

#14 2008-12-16 06:11:16 pm

MadSkillzMan
Member
Registered: 2008-12-16
Posts: 3

Re: Dropdown menu

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

Offline

 

#15 2008-12-16 06:29:52 pm

slacker
Member
Registered: 2006-04-22
Posts: 126
Website

Re: Dropdown menu

MadSkillzMan wrote:

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 sad
give me the code that your using exactly then I can help you for

Offline

 

#16 2008-12-16 10:35:17 pm

MadSkillzMan
Member
Registered: 2008-12-16
Posts: 3

Re: Dropdown menu

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.

Offline

 

#17 2008-12-17 07:35:36 am

hvdwolf
Member
Registered: 2008-09-10
Posts: 60

Re: Dropdown menu

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

Offline

 

#18 2008-12-17 06:54:33 pm

MadSkillzMan
Member
Registered: 2008-12-16
Posts: 3

Re: Dropdown menu

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.

Offline

 

#19 2008-12-17 07:33:26 pm

slacker
Member
Registered: 2006-04-22
Posts: 126
Website

Re: Dropdown menu

Thanks bunch guys! I think i figured it out myself though sad LOL o well i will try this smile bet it's better big_smile

Offline

 

#20 2008-12-18 02:22:10 am

hvdwolf
Member
Registered: 2008-09-10
Posts: 60

Re: Dropdown menu

MadSkillzMan wrote:

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

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".

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.035 seconds, 8 queries executed ]

RSS (new topics) RSS (active topics)