Sudo hangs process

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" as Unicode text
	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)
	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.


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.

I tried this but it dont work:

do shell script "sudo -k; sudo -b " & (quoted form of POSIX path of the_application) & " > /dev/null" with administrator privileges

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.

I cant get it to work.

I readt “Technical Note TN2065 do shell script in AppleScript” and sh man page under “Redirection”, but these unix commands are too kinky to me.

Redirection does not cause a process to run in the background. You usually use an ampersand to run a process in the background:

command &

However, for your usage, you should redirect the output as well. Consider these examples:

-- Background process with output and errors redirected
do shell script "/bin/sleep 10 > /dev/null 2>&1 &"
beep 2

-- Normal process
do shell script "/bin/sleep 10"
beep 2

See also:

So where i put

do shell script “/bin/sleep 10 > /dev/null 2>&1 &”


do shell script “/bin/sleep 10”

I tried to put these to many places in my string but it always fails.

Try something like this:

do shell script (quoted form of POSIX path of the_application) & " > /dev/null 2>&1 &" with administrator privileges