Noob needs help with AppleScript/Eggplant

Hi all,

I'm really new to AppleScript and Eggplant but have found a need to combine the two. I need to show a selection list so that I can choose the correct server to test with Eggplant. I have tried a few different ways of implementing this, but all of them have been unsuccessful. My latest attempt looked like this:
put "" into site
do AppleScript merge of {{
		set [[site]] to choose from list {"Dev", "Staging", "Live"} with prompt ?
		"Choose a server to login to"
}}
if (site = "Dev")
    TypeText "_DEV_URL_"
else if (site = "Staging")
    TypeText "_STAGING_URL_"
else if (site = "Live")
    TypeText "_LIVE_URL_"
else
    TypeText "_DEFAULT_URL_"
end if

However when I run this I get the following error message:
AppleScript Error: Expected expression but found "to".

Running the AppleScript in a stand alone Script Editor seems to work fine, it only complains when it's being run from an Eggplant script.

Could someone please point me in the right direction so that I can return the selection from the list and set it to a variable? Thanks in advance for the help.

Comments

  • SenseTalkDougSenseTalkDoug ForumAdmin admin
    I have two answers to your query.

    The first is this: If you want a user to select an item from among 2 or 3 choices, you don't need to use AppleScript at all -- just use SenseTalk's answer command:
    answer "Choose a server to login to" with "Dev", "Staging", or "Live" \
            title "Please Choose"
    put it into site
    

    SenseTalk doesn't currently offer a way to make a choice among more than 3 items, though -- for that case you'll need to use AppleScript like you were attempting. So my second answer addresses how to do that.

    You were very close, but using the merge function as you did is a way to pass values from SenseTalk to AppleScript, not the other way around. To get resulting values back into SenseTalk, they need to be returned from AppleScript, like this:
    do AppleScript {{ 
    ? ?? ?set aSite to choose from list {"Dev", "Staging", "Live"} with prompt ? 
    ? ?? ?"Choose a server to login to" 
    return aSite
    }}
    put the result into site
    
    Or, using doAppleScript as a function, and recognizing that AppleScript automatically returns its last value, it can be made even simpler:
    set site to doAppleScript of {{ 
    ? ?? ?choose from list {"Dev", "Staging", "Live"} with prompt ? 
    ? ?? ?"Choose a server to login to" 
    }}
    
  • Thank you very much! That's exactly what I needed :D
Sign In or Register to comment.