3

I know this is sloppy code, but here it is:

display dialog ("Start Screensaver. Please type: matrix, coffee, waffles, star, water, or
fireworks.", default answer "")
if text returned of result = "matrix" then
set user_choice to "MatrixSaver"
else
if text returned of result = "coffee" then
    set user_choice to "Coffee"
else
    if text returned of result = "waffles" then
        set user_choice to "Waffles"
    else
        if text returned of result = "star" then
            set user_choice to "Hyperspace"
        else
            if text returned of result = "water" then
                set user_choice to "LotsaWater"
            else
                if text returned of result = "fireworks" then
                    set user_choice to "Skyrocket"
                else
                    (*do nothing*)
                end if
            end if
        end if
    end if
end if
end if

if (user_choice = null) then (*do nothing*)
else
tell application "System Events"
    set ss to screen saver user_choice
    start ss
end tell
end if

When I'm trying to compile my code, the 'default answer' Is highlighted, and it says: "Expected “)”, etc. but found identifier."

Any Ideas? Thanks.

2 Answers 2

2

I believe the correct syntax is just

display dialog "Start Screensaver. Please ..." default answer ""
Sign up to request clarification or add additional context in comments.

Comments

2

The , between the ("Start Screensaver") and the default answer parameter is causing the syntax error. Remove the ,.

This isn't a syntax error, but the variable user_choice doesn't exist outside of the big if block. If you ran it as written, you would get this message at the last if block:

The variable user_choice is not defined.

You could fix this by declaring the variable before the display dialog statement...

set the user_choice to ""

Now you can use the variable anywhere in the code. :)

3 Comments

The second half of your answer is incorrect—AppleScript only has local (function) and global scopes.
@fireshadow25 When I did what you said, 'default' of 'default answer' was highlighted, and the program say that it expected a "," Any Thoughts?
@CodeKid Yeah. The parenthases aren't really needed unless you are evaluating an expression. I'd suggest removing both parentheses from the display dialog statement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.