Problem with my apple script program.

Discussion in 'Mac Apps and Mac App Store' started by dikyman, May 2, 2011.

  1. dikyman macrumors newbie

    Joined:
    May 2, 2011
    #1
    my program is:

    display dialog "VIRUS DETECTED" buttons {"Slow os x to handle virus", "Crash CPU"} default button 2
    if the button returned of the result is "Slow os x to handle virus" then
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}
    diplay dialog "Error, Please force quit" buttons {"Ok"}

    else
    sleep
    end if

    as you can see its for a fake virus. just for fun be I get the error "Expected end of line but found identifier." and it points to the highlighted above word: dialog. how can I fix this?
     
  2. andmr macrumors member

    Joined:
    Aug 25, 2008
    Location:
    NE Florida
    #2
    I haven't tried your script, but my guess is that the word immediately preceding the highlighted word is misspelled: "diplay" should read "display." Good luck.
     
  3. kalsta macrumors 68000

    kalsta

    Joined:
    May 17, 2010
    Location:
    Australia
    #3
    It's been a long, long time since I did anything in Apple Script. Possibly the last time was when I pulled a similar trick on my old boss. That was back in OS 7 or something… I made the script look like his main work folder and when he double clicked on it, it threw a dialog that said something like, 'Are you sure you wish to erase the entire hard drive XXXX'? And the best part was it only had an 'OK' button!!! Oh I was such a funny fellow back then…

    Anyway, aside from the typo, surely you can create some kind of loop rather than repeat the same line 50 times? Basic rule of programming is don't repeat yourself. So, yeah… don't repeat yourself.
     
  4. Jolly Jimmy macrumors 65816

    Jolly Jimmy

    Joined:
    Dec 13, 2007
    #4
    If you want the dialog to loop endlessly to force a force quit just add a repeat. And I take it you want the system to sleep otherwise.

    Code:
    display dialog "VIRUS DETECTED" buttons {"Slow os x to handle virus", "Crash CPU"} default button 2
    if the button returned of the result is "Slow os x to handle virus" then
    	repeat
    		display dialog "Error, Please force quit" buttons {"Ok"}
    	end repeat
    else
    	tell application "Finder" to sleep
    end if
     
  5. Mal macrumors 603

    Mal

    Joined:
    Jan 6, 2002
    Location:
    Orlando
    #5
    This is absolutely the problem. Fix that on all of those repeated lines, and it will work just as expected. The post above mine does show you an easier way to achieve the result, however.

    jW
     

Share This Page