2011-08-18 2 views
-2

방금 ​​전에 AppleScript를 사용하기 시작했으며 10 분 전에 이상한 구문 오류가 발생했습니다. 나는 그냥 바보짓을하고 다음을 생각해 냈다 :AppleScript - 구문 오류

display dialog "Press a button!" buttons{"1","2","3"} 
if the button_pressed is "1" then 
    display dialog "You pressed the first button!" 
else if the button_pressed is "2" then 
    display dialog "You pressed the second button!" 
else 
    display dialog "You pressed the last button!" 
end if 

심지어 실행되지 않는다. 변수가 내 프로그램에 명확하게 나타나면 그냥 button_pressed is not defined 오류가 발생합니다!

+3

AppleScript로 10 분을 소비하고 간단한 오류가 하나 생겨 여기에 게시됩니까? 어서. 최소한 당신이하고있는 일에 약간의 노력을 기울이십시오. -1 –

답변

1

먼저 변수를 설정해야합니다. 이것을 시도하십시오 :

display dialog "Press a button!" buttons {"1", "2", "3"} 
set button_pressed to button returned of the result 
1

글쎄, "프로그램에서"는 반드시 "정의"를 의미하지는 않습니다. 변수가 정의되면 단어 setto이 그 변수를 둘러 쌉니다. 나는 당신의 코드에서 어디에도 그것을 보지 못한다. 이것은 쉽게 재구성됩니다. if 블록 앞에이 줄을 추가하기 만하면됩니다. 그들이 사용하기 전에

set the button_pressed to the button returned of (display dialog "Press a button!" buttons{"1","2","3"}) 

변수 항상가 정의되어야합니다

set the button_pressed to the button returned of the result 

... 또는 더 나은 .... 세 가지 예외는 property s, global 변수 및 local 변수입니다 (AppleScript를 계속 사용하는 경우 나중에 이에 대해 알 수 있습니다 :)).