2010-01-07 3 views
1

아내가 mt-daapd를 실행하고 쉽게 종료 할 수 있도록 두 개의 applescript를 작성했습니다. 스크립트 편집기 앱에서는 제대로 작동하지만 독립형 앱으로 컴파일하면 테스트 한 첫 번째 앱에서 작동합니다. 그런 다음 나는 자랑스럽게 내 아내에게 보여줄 때 나를 부끄럽게 만듭니다. 나는 "열린"애니메이션을보고 그들은 단지 거기에 앉아 있습니다. 이전에 다른 독립형 앱을 만들었지 만 이런 일은 일어나지 않았습니다.시작시 종료되는 컴파일 된 AppleScript를 어떻게 진단합니까?

앱 유형을 번들로 변경하려고했습니다 (동일한 문제). 심지어 gdb를 통해 실행 파일에 연결하여 어떤 일이 일어나고 있는지 알려주는 마술을 깰 수 있는지 알아보기까지했습니다. 콘솔에서 몇 가지 정보를 찾았습니다. 아무것도 스크립트는 내 얼굴에 웃었다.

이 문제를 어떻게 해결합니까?

다음 스크립트 중 하나를 포함 시켰습니다. 두 번째는 거의 동일합니다. 나는 10.5.8을 달리고있다.

property userpassword : "" 

if userpassword is "" then 
    display dialog "Please enter your user password:" default answer "" with hidden answer 
    set userpassword to text returned of result 
    set the_password to "Undefined" 
    repeat until the_password is "Correct" 
     try 
      do shell script "/opt/local/sbin/mt-daapd -c /etc/mt-daapd.conf" password userpassword with administrator privileges 
      set the_password to "Correct" 
     on error 
      display dialog "Sorry, the password entered was not correct. Please try again:" default answer "" with hidden answer 
      set userpassword to text returned of result 
     end try 
    end repeat 
    if the_password is "Correct" then 
     display dialog "Your music is being shared!" buttons {"Done"} default button "Done" 
    end if 
end if 

답변

1

나는 이런 일이 있지만 그것은 어떤 값으로 설정되어있는, 그래서 일단 스크립트가 호출 사이 userpassword의 값을 저장하는 방법을 잘 모르겠어요, 그 값을 유지 그냥 프로그램을 종료합니다. 다른 독립 실행 형 응용 프로그램을 어떻게 작성했는지 살펴본 후이를 발견했습니다.

+0

일반 애플 스크립트에서, 모든 글로벌 변수는 스크립트로 저장됩니다. –

1

속성은 고정되어 있지 않으며 다른 개체의 속성과 같습니다. 런타임에 변경하거나 다른 스크립트에서 변경할 수 있습니다. 그래서 당신의 script1이는

property potato: "potayto" 
say potato 

이고 당신이 당신의 컴퓨터가 "potahto을"말을 만들 것 다시 script1이 실행 후 다른 스크립트를

set potato of script1 to "potahto" 

를 실행합니다.

속성은 스크립트에 환경 설정을 저장하는 유용한 방법 일 수 있습니다.

첫 번째 if 문을 삭제하면 중복됩니다. 암호가 비어 있지 않은지 확인하십시오. 따라서

:

property userpassword :"" 
set the_password to "Undefined" 
repeat until the_password is "Correct" 
    try 
     do shell script "/opt/local/sbin/mt-daapd -c /etc/mt-daapd.conf" password userpassword with administrator privileges 
     set the_password to "Correct" 
    on error 
     display dialog "Sorry, the password was not correct. Please try again:" default answer "" with hidden answer 
     set userpassword to text returned of result 
    end try 
end repeat 
if the_password is "Correct" then 
    display dialog "Your music is being shared!" buttons {"Done"} default button "Done" 
end if 
+1

보안을 강화하기 위해 키 체인 스크립팅을 조사하거나 명령 행 기능 "security"를 조사 할 수 있습니다. – stib

관련 문제