Applescript help

Discussion in 'Mac Programming' started by Yeroc8, Mar 4, 2015.

  1. Yeroc8 macrumors newbie

    Joined:
    Mar 4, 2015
    #1
    When I run my code, the list pops up and I make a selection, but nothing happens.

    My code:
    Code:
    set showOrHide to choose from list {"Show system files", "Hide system files"} with prompt "Please make your selection" without multiple selections allowed and empty selection allowed
    	return the result as string
    	if showOrHide is false then
    		error number -128
    	else if showOrHide contains "Show system files" then
    		set userChose to "Show system files" as text
    	else if showOrHide contains "Hide system files" then
    		set userChose to "Hide system files" as text
    	end if
    	if userChose is "Show system files" then
    		do shell script "defaults write com.apple.finder AppleShowAllFiles YES"
    	else if userChose is "Hide system files" then
    		do shell script "defaults write com.apple.finder AppleShowAllFiles NO"
    	end if
     
  2. HexMonkey Administrator

    HexMonkey

    Staff Member

    Joined:
    Feb 5, 2004
    Location:
    New Zealand
    #2
    You need to remove the "return" statement on the second line. Calls to return in that context will immediately end the script (with the return value as the result).
     
  3. Bruno09, Mar 4, 2015
    Last edited: Mar 4, 2015

    Bruno09 macrumors 68020

    Joined:
    Aug 24, 2013
    Location:
    Far from here
    #3
    Hi,

    what is your goal ? Show/Hide hidden files ?

    Code:
    set retour to (return & return)
    set theTexte to ("Hidden files" & retour)
    
    display dialog theTexte buttons {"Reveal", "Hide", "Cancel"} default button 3 with icon 2
    
    set resultat to button returned of the result
    
    if (resultat = "Reveal") then
    	do shell script "defaults write com.apple.finder AppleShowAllFiles 1
    killall Finder"
    	
    else if (resultat = "Hide") then
    	do shell script "defaults write com.apple.finder AppleShowAllFiles 0
    killall Finder"
    	
    else
    	quit
    end if
     

Share This Page