Else If works in applescript editor, not in Automator

I’m stuck. I’m trying to write a simple applescript that will allow me to achieve branching in Automator. I just want to display a dialog that will allow the user to choose which route to take. Below is my applescript. This script works perfectly in Applescript Editor and returns the proper alias. But when I put it into a Run Applescript action in Automator, it will not return a result. The action does not display an error and appears to successfully complete, but no result is returned. In this example, I have created a folder on my desktop called “Workflows” and put the two referenced workflow files in in.

I’m pretty new at applescript. Any ideas why the action won’t return a result? Thanks


set theiPad to (path to desktop folder as string) & "Workflows:iPad.workflow" as alias
set theTape to (path to desktop folder as string) & "Workflows:Tape_Bin.workflow" as alias

display dialog "Are you use the iPad or the Tape Bin?" buttons {"iPad", "Tape Bin"}
if result = {button returned:"iPad"} then
	return theiPad
else if result = {button returned:"Tape Bin"} then
	return theTape
end if

Model: macbook pro
AppleScript: 2.2.3
Browser: Safari 536.26.17
Operating System: Mac OS X (10.8)

Hello.

The result is a kind of volatile entity, so it may very well be that the result is overwritten by the first clause in the if test. Please try this instead:

display dialog "Are you use the iPad or the Tape Bin?" buttons {"iPad", "Tape Bin"} default button 2
set btn to button returned of the result
if btn = "iPad" then
	return "theiPad"
else if btn = "Tape Bin" then
	return "theTape"
end if

Hi,

the problem is that the result is never just {button returned:“something”} in Automator.
display dialog in Automator returns always the full record {button returned:“”, text returned:“”, gave up:false}, so you should use something like


on run {input, parameters}
	
	set theiPad to (path to desktop folder as string) & "Workflows:iPad.workflow" as alias
	set theTape to (path to desktop folder as string) & "Workflows:Tape_Bin.workflow" as alias
	
	set buttonReturned to button returned of (display dialog "Are you use the iPad or the Tape Bin?" buttons {"iPad", "Tape Bin"})
	if buttonReturned = "iPad" then
		return theiPad
	else if buttonReturned = "Tape Bin" then
		return theTape
	end if
end run

Nice to know Stefan. :slight_smile:

Thanks to the both of you! Worked like a charm.