Applescript dialog not working in Automator

Discussion in 'Mac Programming' started by macstatic, Mar 22, 2016.

  1. macstatic macrumors 6502a

    Joined:
    Oct 21, 2005
    #1
    What's wrong with the following Applescript (it works fine in the Applescript editor) when I use it with Automator?:
    Code:
    display alert "Bold title here" as warning message "More text here" buttons {"OK"} default button "OK"
    It looks like this in the "Run Applescript" Automator action -I've just pasted the Applescript into where it says (* Your script goes here *):
    Code:
    on run {input, parameters}
     
        (display alert "Bold title here" as warning message "More text here" buttons {"OK"} default button "OK")
     
        return input
    end run
    The error message I get is:

    Syntax error
    Expected “,” but found “"”.
     
  2. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #2
    I think a more interesting question is why it works outside Automator. In short, the syntax of the display alert command is wrong. It should be something like:

    Code:
    on run {input, parameters}
    
       display alert "Bold title here" message "More text here" as warning buttons {"OK"} default button "OK"
       return input
    
    end run
    
    ...note the position of the "as warning". If in doubt, always take a peek in the scripting dictionary:


    display alert
    display alert (verb)Display an alert (from the User Interaction suite, defined in StandardAdditions.osax)

    function syntax
    set theResult to display alert text ¬
    message text ¬
    as as ¬
    buttons list of text ¬
    default button text or integer ¬
    cancel button text or integer ¬
    giving up after integer
    message text ¬
    as as ¬
    buttons list of text ¬
    default button text or integer ¬
    cancel button text or integer ¬
    giving up after integer
    message text ¬
    as as ¬
    buttons list of text ¬
    default button text or integer ¬​
    cancel button text or integer ¬
    giving up after integer
    result
    alert replya record containing the button clicked​
     
  3. macstatic thread starter macrumors 6502a

    Joined:
    Oct 21, 2005
    #3
    Thanks! That worked fine (in both AppleScript editor and Automator) but I'm unable to find the scripting dictionary you're referring to and none of the links above work.
    I was hoping to further figure out how to use custom app icons as I've successfully done that in Applescript in combination with the two dialog lines (the first one being bold) as in my above script:

    Code:
    display dialog "Backup done!" with icon file "Applications:Utilities:Terminal.app:Contents:Resources:Terminal.icns" buttons "OK" default button "OK"
    Apparently it's not a simple matter of inserting "with icon file....." after the text and removing "as warning"
     
  4. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #4
    Sorry. I probably confused the issue by copying and pasting out of Script Debugger.

    If you're in Script Editor then go to File>Open Dictionary and look for "Standard Additions". The documentation for the display alert command is in there.

    I don't think display alert lets you supply an icon file, but display dialog does.
     
  5. macstatic, Mar 23, 2016
    Last edited: Mar 23, 2016

    macstatic thread starter macrumors 6502a

    Joined:
    Oct 21, 2005
    #5
    OK, I found the dictionary in the Applescript editor where I opened "Standard additions" -it seems you're right: there isn't an option for adding custom icons to display alert though with display dialog it's possible.
    Hmmmm..... I'm a little confused myself.. I can't seem to find any of my Applescript files containing both a bold title with a normal 2nd line of text (display alert) along with a custom icon (display dialog), so perhaps it's not even possible in Applescript either.

    I came across some interesting reading in this posting where the answer seems to indicate that the code
    using terms from application "Finder" can be used to make Automator accept standard Applescript code. If my understanding is correct, this could possibly be used for any Applescript code which otherwise wouldn't work in Automator, but if the code won't work in Applescript itself to begin with that won't be of any use :confused:

    Maybe I should just settle for the easier to read message (bold title, normal 2nd line of text) with a standard icon :)
     

Share This Page