0

I made a simple AppleScript that launches a different set of apps depending on user input. I am new to AppleScript and it is tweaked from a bunch I found on the internet, modified for my usage. It is included below.

What it should do: Buttons 2 and 3 simply launches various sets of apps, while button 1 checks if Spotify is running, and if it is, switches to it. If it isn't, open 3 apps (including Spotify).

However I get an "Expected end of line, etc. but found end of script." error when compiling. Here is the script. What is wrong with it?

set question to display dialog "What do you want to launch?" buttons {"Spotify", "MiniPlayer", "Remote"} default button 1
set answer to button returned of question

if answer is equal to "Spotify" then
    set myAppName to "Spotify"
    set isRunning to false
    tell application "System Events"
        if exists process myAppName then
            set isRunning to true
        end if
    end tell
    if isRunning is true then
        tell application myAppName to activate
    else
        tell application "Spotify" to activate
        tell application "Spotifree" to activate
        tell application "Spotify Notifications" to activate
    end if
end if
if answer is equal to "MiniPlayer" then
    tell application "MiniPlayer" to activate
end if
if answer is Equal to "Remote" then
    set question to display dialog "What remote do you want to launch?" buttons {"IR Remote", "Android", "Both"} default button 2
set answer to button returned of question
    if answer is equal to "IR Remote" then
    tell application SpotifyIrRemote to activate    
    if answer is equal to "Android"
        tell application RemotelessHelper to activate   
    if answer is equal to "Both"
        tell application SpotifyIrRemote to activate
        tell application RemotelessHelper to activate
    end if
end if
  • Which "end if" belongs to the "if answer is equal to Spotify" condition? – nohillside Apr 28 '14 at 13:30
  • @patrix I seem to have forgotten the end if. I have edited it, it is the second "end if" above the code "if answer is equal to "MiniPlayer" then" – Johnny Apr 28 '14 at 13:48
  • That was kind of rhetorical to get you started with counting if...thens and end ifs, but you got the answer below already :-) – nohillside Apr 28 '14 at 14:02
  • @patrix Thanks for that - it was a good way to get me figuring things out on my own. Sometimes errors are hard to spot by myself. – Johnny May 24 '14 at 9:27
0

You are missing a bunch of end ifs and 2 then.

set question to display dialog "What do you want to launch?" buttons {"Spotify", "MiniPlayer", "Remote"} default button 1
set answer to button returned of question

if answer is equal to "Spotify" then
    set myAppName to "Spotify"
    set isRunning to false
    tell application "System Events"
        if exists process myAppName then
            set isRunning to true
        end if
    end tell
    if isRunning is true then
        tell application myAppName to activate
    else
        tell application "Spotify" to activate
        tell application "Spotifree" to activate
        tell application "Spotify Notifications" to activate
    end if
end if

if answer is equal to "MiniPlayer" then
    tell application "MiniPlayer" to activate
end if

if answer is equal to "Remote" then
    set question to display dialog "What remote do you want to launch?" buttons {"IR Remote", "Android", "Both"} default button 2
    set answer to button returned of question
    if answer is equal to "IR Remote" then
        tell application SpotifyIrRemote to activate
    end if
    if answer is equal to "Android" then
        tell application RemotelessHelper to activate
    end if
    if answer is equal to "Both" then
        tell application SpotifyIrRemote to activate
        tell application RemotelessHelper to activate
    end if
end if

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .