Earlier LetterStick (part of HenWen) started without errors, but now i need to run this script to get it running.
If i run this script, it does its thing, but it makes script itself as Not Responding and it must be force quitted.
What this means, so is -K safer than -k?
“The -K (sure kill) option is like -k except that it removes the user’s timestamp entirely.”
set the_application to "Macintosh HD:Applications:HenWen:LetterStick.app:" as Unicode text
try
set the_application to the_application & "Contents:MacOS:"
set executable_files to (list folder the_application)
repeat with i from 1 to (count executable_files)
set this_item to item i of executable_files
if this_item does not start with "." then
set the_application to the_application & this_item
exit repeat
end if
end repeat
do shell script "sudo -k; sudo -b " & (quoted form of POSIX path of the_application) with administrator privileges
on error
return my display_error("There was an error opening the file you used. Please try again.")
end try
on display_error(e)
beep
activate
display dialog e buttons {"OK"} default button 1 with icon 0 giving up after 20 with title "error message here"
end display_error
“Do shell script” waits for the shell command to return. When you launch a package’s executable from the shell, the executable does not return immediately. The command as you have it will wait for the executable to finish and return a result code.
Also:
You do not need sudo when invoking “with administrator privileges”, so don’t use it. They are not the same thing, and using them together is a security risk.
What did you expect to have happen? “sudo -k” kills sudo permissions, and sudo -b would have made the process following it a background process.
Don’t use sudo from AppleScript.
When sudo is invoked, it has a timeout (unless you reset it) of 5 minutes. That means that any other process following it in a script that requires root privilege will get it without a password. Before 10.4, it was good practice to use do shell script "sudo … " and then when the task was complete, follow it with do shell script “sudo -k” to turn off the access to root just opened. Using with administrative privilege does not require that step - it terminates with the spawned process terminates.
You would probably make more progress by reading the documentation I posted, rather than trying random stuff blindly.
It was never good practice to use “sudo” and “with administrator privileges” together to execute commands, but in 10.3.9 and prior, it was good to close the timestamp hole with “sudo -k” (sans “with administrator privileges”). This was due to a bug in Mac OS X that has since been fixed.