Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

JPinto

macrumors newbie
Original poster
Jan 12, 2013
1
0
Hello, Im new to AppleScript programming and having some trouble trying to get the returned result of the clicked button

I have a list of list of items, and two buttons (Show, Hide). I want to do an If then else statement depending on if the button selected was show or Hide... Here is an example of what im trying to do..


Code:
set SelectedItem to (choose from list {"User Library", "Hidden Files", "Something1", "Thinking"} with prompt "Choose" with title "Show/Hide" OK button name "Show" cancel button name "Hide")

if SelectedItem is "User Library" then 
[INDENT]IF Button Returned of Result is "SHow" THEN  DO SHELL Script "Show    example"[/INDENT]
[INDENT]IF BUtton returned of Result is "Hide" THEN DO SHELL SCRIPT "Hide Example"[/INDENT]

IF SelectedItem is "Hidden file" THEN
[INDENT]IF Button Returned of Result is "SHow" THEN  DO SHELL SCHRIPT "Show Hidden"
IF BUtton Reutned of Result if "Hide" THEN DO SHELLS CRIPT "Hide Hidden"[/INDENT]
	
--Continue for Each List Item and Button Option
Right now, with that list I cant even (Display Dialog) the Button Returned of Result.. i would get this error:

error "Can’t get button returned of {\"User Library\"}." number -1728 from button returned of {"User Library"}

I would select "User Library" from the List
and then Select the Button "Show" Expecting the Display dialog box to show "Button Returned Show"


I'm usually doing Visual Basic or SQL and apple script is new to me, so any help would be wonderful

Thank you.
 

Mark FX

macrumors regular
Nov 18, 2011
159
17
West Sussex, UK
The choose from list command returns either false, or a list of chosen items, so you have to check the returned list for the items you want to check.

Like this.

Code:
set chosen_city to choose from list {"New York", "Boston", "Chicago"}
if chosen_city is false then
	return "Cancelled Button Clicked" as text
else if chosen_city contains "New York" then
	return "You chose New York" as text
else
	return "You did not choose New York" as text
end if

The reason it returns a list, is that you can set the choose from list command
to allow multiple selections.

Like this.

Code:
set chosen_city to choose from list {"New York", "Boston", "Chicago"} with multiple selections allowed
if chosen_city is false then
	return "Cancelled Button Clicked" as text
else
	return chosen_city count
end if

If the user clicks the Cancel button it basically returns false, but you can use it to return the user canceled error number 128.

like this.

Code:
set chosen_city to choose from list {"New York", "Boston", "Chicago"}
if chosen_city is false then
	error number -128
else if chosen_city contains "New York" then
	return "You chose New York" as text
end if

So in short your line of code here.
Code:
if SelectedItem is "User Library" then

Should be.
Code:
if SelectedItem contains "User Library" then

Hope this helps

Regards Mark
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.