如何诊断在启动时退出的已编译Applescript?
我写了两个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
我不知道这是怎么发生的,但因此一旦它已经被设置为任意值的脚本保存的userpassword
调用之间的值,它保留了价值,只是退出程序。在查看我如何创建其他独立应用程序后,我发现了这一点。
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
您可能希望调查钥匙串脚本以使其更安全,或命令行功能“安全”。 – stib 2010-01-13 01:07:47
在正规的AppleScript,所有的全局变量都保存与脚本。 – 2011-12-08 02:40:20