Dialog Variable not Defined?

Discussion in 'Mac Programming' started by ness64, Sep 12, 2013.

  1. ness64, Sep 12, 2013
    Last edited by a moderator: Sep 12, 2013

    ness64 macrumors newbie

    Joined:
    Sep 12, 2013
    #1
    Hello,
    I am new here. I'm sorry if this is a nooby question. I was making a script on AppleScript, but it keeps on telling me the variable is undefined whenever I click on a dialog box button.
    Here is the script. The line of question will have an arrow next to it.
    Code:
    tell application "Safari"
    	quit
    end tell
    set app_name to "QuickTime Player"
    --do shell script "killall " & app_name
    tell application "QuickTime Player"
    	activate
    	set volume 10
    	tell (new movie recording)
    		start
    		do shell script "say -v trinoids Virus activated"
    		set volume 10
    		do shell script "say -v trinoids All your Base are belong to us"
    		tell application "Finder"
    			activate
    			repeat 50 times
    				make new Finder window
    			end repeat
    		end tell
    		tell application "Safari"
    			open location "http://www.youtube.com/watch?v=oHg5SJYRHA0"
    			set volume 10
    		end tell
    		
    		display dialog "Virus propagating.
    Plan of action?" buttons {"Seek and Destroy Virus", "Self Destruct"}
    		stop
    	end tell
    	set MovieFile to (file of document of front window) as alias
    	close front window saving yes
    end tell
    if the button returned of result is "Self Destruct" then <====
    	tell application "System Events" to (sleep) and (stop) and application "Finder"
    	move MovieFile to desktop
    	set name of MovieFile to "LOL.mov"
    else
    	set volume 10
    	stop and application "Finder"
    	move MovieFile to desktop
    	set name of MovieFile to "LOL.mov"
    	do shell script "say -v zarvox requesting authorisation for M,A,D, weapons strike"
    	do shell script "shutdown -h now" with administrator privileges
    end if
    
    Thanks! :)
     
  2. Red Menace macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #2
    The special variable result contains the result of the last operation. You are doing a couple of other things before dealing with the dialog results, so there probably isn't a button returned property in the current result.

    If you aren't going to immediately do stuff with the results of a dialog, you should save it to a variable, for example:
    Code:
    set dialogResult to (display dialog "whatever" buttons {"someButton", anotherButton"})
    -- other statements
    if button returned of dialogResult is "someButton" then
      -- deal with dialog result
    end if
    
     
  3. ness64 thread starter macrumors newbie

    Joined:
    Sep 12, 2013
    #3
    Thanks! It works so far! However, I've encountered another problem. When I added some code to make the brightness of the screen go to 0, it gives me a stack overflow error. Help? I'll make the line of question red.

    Code:
    tell application "Safari"
    	quit
    end tell
    set app_name to "QuickTime Player"
    --do shell script "killall " & app_name
    tell application "QuickTime Player"
    	activate
    	set volume 1
    	tell (new movie recording)
    		start
    		do shell script "say -v trinoids Virus activated"
    		set volume 1
    		do shell script "say -v trinoids All your Base are belong to us"
    		tell application "Finder"
    			activate
    			repeat 1 times
    				make new Finder window
    			end repeat
    		end tell
    		tell application "Safari"
    			open location "http://www.youtube.com/watch?v=oHg5SJYRHA0"
    			set volume 1
    		end tell
    		set dialogResult to (display dialog "Virus propagating.
    Plan of action?" buttons {"Seek and Destroy Virus", "Self Destruct"})
    		stop
    	end tell
    	set MovieFile to (file of document of front window) as alias
    	close front window saving yes
    end tell
    if the button returned of dialogResult is "Self Destruct" then
    	[COLOR="Red"]set name of MovieFile to "LOL.mov"[/COLOR]
    	set V to 0
    	tell application "System Preferences"
    		activate
    		set current pane to pane "com.apple.preference.displays"
    	end tell
    	tell application "System Events"
    		tell process "System Preferences"
    			tell slider 1 of group 2 of tab group 1 of window 1
    				set value to V
    			end tell
    		end tell
    	end tell
    	set app_name2 to "Finder"
    	--do shell script "killall"& app_name2
    	do shell script "say -v LOLOLOLOLOLLOLOLOLOLOLOLOLOL"
    else
    	set volume 10
    	move MovieFile to desktop
    	set name of MovieFile to "LOL.mov"
    	do shell script "say -v zarvox requesting authorisation for M,A,D, weapons strike"
    	do shell script "shutdown -h now" with administrator privileges
    end if
     
  4. Red Menace macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #4
    I can't run your script, but you are not going to be able to move or rename files outside of an application tell statement.
     

Share This Page