2010-01-07 38 views
1

我寫了兩個applescripts,以便我的妻子可以輕鬆地啓動mt-daapd並關閉它。它們在腳本編輯器應用程序中運行良好,但是當我將它們編譯爲獨立應用程序時,這些應用程序會在我第一次測試它們時運行。然後他們讓我難堪,因爲我驕傲地向我的妻子炫耀他們。我看到「開放」動畫,然後他們就坐在那裏。我之前創建了其他獨立應用程序,但這並未發生。如何診斷在啓動時退出的已編譯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

在正規的AppleScript,所有的全局變量都保存與腳本。 – 2011-12-08 02:40:20

1

applescripts中的屬性不固定,它們就像任何其他對象的屬性。您可以在運行時更改它們,或從另一個腳本中調用它們。所以如果你的SCRIPT1是

property potato: "potayto" 
say potato 

,你跑了另一個腳本

set potato of script1 to "potahto" 

然後再次運行SCRIPT1將讓你的電腦說: 「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

您可能希望調查鑰匙串腳本以使其更安全,或命令行功能「安全」。 – stib 2010-01-13 01:07:47

相關問題