2014-01-17 5 views
0

저는 AppleScript 코딩에 새로운 것이므로이 코드에 어떤 문제가 있는지 궁금합니다. 오류는 "변수 결과가 정의되지 않았습니다."입니다. 오류가 발생하는 이유는 무엇입니까? 내 코드는 다음과 같습니다 : 문, 그들은 3 가능한 버튼 선택을 잡으려고 올바른 구조를 얻기 위해 else if와 함께 묶여 될 필요가있는 경우변수 결과가 정의되지 않았습니다.

display dialog "Hello and welcome to my app!" buttons {"Login", "Quit"} default button 1 

if the button returned of the result is "Login" then 
    display dialog "Username:" buttons {"Raphi", "Guest"} default button 1 with title  "Choose user" 
else 
    tell application "My app" to quit 
end if 
if the button returned of the result is "Raphi" then 
display dialog "Password:" default answer "" buttons {"Submit"} with title "Enter password" with hidden answer 
else 
display dialog "You have selected guest! Guest is not currenty enabled, please ask  Raphi to enable it. Thank you!" buttons {"OK"} 
end if 
if the text returned of the result is "123" then 
display dialog "Would you like to continue or exit?" buttons {"Continue", "Exit"} 
else 
display dialog "Incorrect password" buttons {"OK"} default button 1 with icon stop 
end if 
if the button returned of the result is "OK" then 
tell application "My app" to quit 
end if 
if the button returned of the result is "Continue" then 
display dialog "" 
else 
tell application "My app" to quit 
end if 

답변

1

오류가 지난 몇했다.

tell application "My app" to quitreturn으로 변경했습니다. 이 스크립트의 실행을 종료하고 종료합니다 (참고 : 앱으로 저장할 경우, 숙박에 설정을하지 않는 개방)

그것으로 테스트 스크립트 편집기를 종료 아니지만 또한 도움이 것이 스크립트를 실행할 때마다 또는 quit으로이 블록을 단순화 할 수는 있지만, return이 더 깨끗하다고 ​​생각합니다.

display dialog "Hello and welcome to my app!" buttons {"Login", "Quit"} default button 1 

if the button returned of the result is "Login" then 
    display dialog "Username:" buttons {"Raphi", "Guest"} default button 1 with title "Choose user" 
else 
    return 
end if 

if the button returned of the result is "Raphi" then 
    display dialog "Password:" default answer "" buttons {"Submit"} with title "Enter password" with hidden answer 
else 
    display dialog "You have selected guest! Guest is not currenty enabled, please ask  Raphi to enable it. Thank you!" buttons {"OK"} 
    return 
end if 

if the text returned of the result is "123" then 
    display dialog "Would you like to continue or exit?" buttons {"Continue", "Exit"} 
else 
    display dialog "Incorrect password" buttons {"OK"} default button 1 with icon stop 
end if 

if the button returned of the result is "OK" then 
    return 
else if the button returned of the result is "Continue" then 
    display dialog "" 
else 
    return 
end if 
0

대신이 시도 :

아래 수정을 참조하십시오

if button returned of dialogResult is ... then 
:

set dialogResult to display dialog ... 

후 리턴 값을 확인

관련 문제