Monday, July 23, 2018
  • Index
  •  » Automator
  •  » Else If works in applescript editor, not in Automator

#1 2013-03-23 10:49:24 am

miabifilms
Member
Registered: 2013-02-06
Posts: 7

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


Applescript:


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)

Last edited by miabifilms (2013-03-23 10:51:28 am)


Filed under: Automator, else if, branching

Offline

 

#2 2013-03-23 12:09:45 pm

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Else If works in applescript editor, not in Automator

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:

Applescript:

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


Filed under: result

Offline

 

#3 2013-03-23 12:38:09 pm

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11499
Website

Re: Else If works in applescript editor, not in Automator

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

Applescript:


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


regards

Stefan

Offline

 

#4 2013-03-23 01:07:46 pm

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Else If works in applescript editor, not in Automator

StefanK wrote:

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

Applescript:


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

Offline

 

#5 2013-03-23 06:58:25 pm

miabifilms
Member
Registered: 2013-02-06
Posts: 7

Re: Else If works in applescript editor, not in Automator

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

Offline

 
  • Index
  •  » Automator
  •  » Else If works in applescript editor, not in Automator

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)