applescript - try

Discussion in 'Mac Programming' started by Lokrado, Jan 19, 2010.

  1. Lokrado macrumors regular

    Joined:
    Jan 26, 2009
    Location:
    Denmark
    #1
    So I made this application to remove a known virus that comes with a cracked version of photoshop CS4, I personally don't have the virus myself. I was just making this tool based on integos press release.

    Anyway I think my error is in the very first try, when it follows the error line down to the ok (quit) button, but the app continues t execute script further down causing unwanted dialogs

    I would much appreciate any help on this concern, since this is my very first applescript! :)

    Thank you! :)

    Code:
    set return_value to display dialog "Removing virus" with icon caution buttons {"Do it!", "No don't!", "Check manually"} default button 1 with title "Virus Remover"
    
    set answer to button returned of return_value
    
    if answer = "Do it!" then
    	try
    		try
    			do shell script "rm /var/tmp/tmp.*" with administrator privileges
    		on error
    			try
    				do shell script "rm /usr/bin/DivX*" with administrator privileges
    			on error
    				try
    					do shell script "rm /System/Library/Startupitems/DivX*" with administrator privileges
    				on error
    					set return_value to display dialog "No virus found in subsequent directories!" with icon 2 buttons {"Ok"} default button 1 with title "Good!"
    					
    					set answer to button returned of return_value
    					
    					if answer = "Ok" then
    						quit
    					end if
    				end try
    			end try
    		end try
    		try
    			do shell script "rm /usr/bin/DivX*" with administrator privileges
    		on error
    			try
    				do shell script "rm /System/Library/Startupitems/DivX*" with administrator privileges
    			on error
    				set return_value to display dialog "Virus found and deleted in /var/tmp/ but none in subsequent directories" with icon 2 buttons {"Ok"} default button 1 with title "Partial success"
    				set answer to button returned of return_value
    				
    				if answer = "Ok" then
    					quit
    				end if
    			end try
    		end try
    		try
    			do shell script "rm /System/Library/Startupitems/DivX*" with administrator privileges
    		on error
    			set return_value to display dialog "virus found and deleted in /var/tmp/ and /usr/bin but none in subsequent folders" with icon 2 buttons {"Ok"} default button 1 with title "Partial success"
    			set answer to button returned of return_value
    			
    			if answer = "Ok" then
    				quit
    			end if
    		end try
    	on error
    		set return_value to display dialog "Virus found and deleted in /var/tmp/, /usr/bin and /System/Library/Startupitems, you are safe for now!..." buttons {"Ok"} default button 1 with title "Success"
    		set answer to button returned of return_value
    		
    		if answer = "Ok" then
    			quit
    		end if
    	end try
    else if answer = "Check manually" then
    	do shell script "open /var/tmp"
    	do shell script "open /usr/bin"
    	do shell script "open /System/Library/Startupitems"
    	set return_value to display dialog "In the folder /var/tmp/ the virus is an Unix executable (.exec) which name starts with tmp. then something random like: 0.4hs82h. In /usr/bin and /System/Library/Startupitems it is called 'DivX' that's sadly all I know" buttons {"Ok", "More Information"} default button 1 with title "Info"
    	
    	set answer to button returned of return_value
    	
    	if answer = "More Information" then
    		tell application "Safari"
    			open location "http://www.intego.com/news/ism0902.asp"
    		end tell
    	else
    		quit
    	end if
    else
    	quit
    end if

    edit, seems you would have to copy paste it into applescript editor to view it with markup.coloring....
     
  2. sammich macrumors 601

    sammich

    Joined:
    Sep 26, 2006
    Location:
    Sarcasmville.
    #2
    Using the [ code ] [ /code ] tags would help as well.

    That said, it would be easier to see the code markup/colouring in Applescript Editor...

    EDIT: not sure if this helps, but maybe try 'stop' instead of 'quit.
     
  3. Lokrado thread starter macrumors regular

    Joined:
    Jan 26, 2009
    Location:
    Denmark
    #3
    stop/quit

    should do the same, when i run the script from the editor i get an error telling me i cant quit while its running, but that would still normally stop it...while running as an app it just continues...
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    You do realize there's already removal tools right? Why would you want to help pirates anyways?
     
  5. Lokrado thread starter macrumors regular

    Joined:
    Jan 26, 2009
    Location:
    Denmark
    #5
    lol

    yes i do and i don't care, it was simply the first thing i found that i could write an app for that wouldn't be completely useless, learning by doing so happens to be the way i learn.
     
  6. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #6
    Try changing your stop or quit statements to return.
     
  7. Lokrado thread starter macrumors regular

    Joined:
    Jan 26, 2009
    Location:
    Denmark
    #7
    Thanks

    works perfectly thank you!
     

Share This Page