views:

41

answers:

3

I wrote two applescripts so that my wife could launch mt-daapd and shut it down easily. They work fine in the Script Editor app but when I compile them into stand-alone apps, the apps work the first time I test them. Then they embarrass me as I proudly show them off to my wife. I see the "open" animation and then they just sit there. I've created other stand-alone apps before and this hasn't happened.

I tried changing the app type to a bundle (same problem). I even tried attaching to the executable via gdb to see if I could break on something magic to tell me what was going on. I looked in the Console for some information. Nothing was ther The scripts laughed in my face.

How do I fix this problem?

I've included one of the scripts below; the second is pretty much the same. I'm running 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
A: 

This thread has a generic error logger that you can implement: MacScripter / How to debug a droplet.

songdogtech
+1  A: 

I'm not sure how this is happening but the script is saving the value of userpassword between calls so once it has been set to whatever value, it retains that value and just exits the program. I discovered this after looking at how I created my other stand alone apps.

Avry
+1  A: 

properties in applescripts are not fixed, they're like the properties of any other object. You can change them at run time, or evn from another script. so if your script1 was

property potato: "potayto"
say potato

and you ran another script

set potato of script1 to "potahto"

then running script1 again would make your computer say "potahto".

Properties can be useful ways of storing preferences in scripts.

Just delete the first if statement, it's redundant anyway. Check if the password is correct, rather than if it is empty.

thus:

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
You might want to investigate keychain scripting to make this more secure, or the command line function "security".
stib