Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 12, 2013, 06:25 PM   #1
JPinto
macrumors newbie
 
Join Date: Jan 2013
AppleScript - Button Returned of Results from a List

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 
IF Button Returned of Result is "SHow" THEN DO SHELL Script "Show example"
IF BUtton returned of Result is "Hide" THEN DO SHELL SCRIPT "Hide Example"
IF SelectedItem is "Hidden file" THEN
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"
--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.
JPinto is offline   0 Reply With Quote
Old Jan 13, 2013, 02:02 PM   #2
Mark FX
macrumors member
 
Join Date: Nov 2011
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 by Mark FX; Jan 13, 2013 at 02:12 PM.
Mark FX is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:50 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC