AppleScript helper app?

For a variety of reasons, I want to create a AppleScript applet “helper app” that I will use from another app to run shell script with admin privileges. I just need to keep it open for a short time, and want to do it this way so that there’s only one authentication prompt, rather than one each time I run this script.

What I’m unclear on is:

  1. How do I structure the AppleScript applet to receive a message with a file specifier or string as a parameter?

  2. How do I call a particular handler? (This could be done using another AppleScript.)

  3. Is there a way to make it a faceless background app, so the user isn’t distracted by seeing a strange icon pop up in the dock?

Thanks in advance!

Hi treed,

Try looking at this post:
http://macscripter.net/viewtopic.php?id=19378
x is the name of the caplet you want to run.

Edited: and remember to save the droplet as stay open.

Edited: for background only, add this to the applications info.plist:

The info.plist is in the package.

Edited: there are several ways, I think, that you can have the open handler run different subroutines. It depends on why you want to run a certain subroutine. For instance, you might want to run them in a sequence.

Edited: are you running a handler, depending on the user info? Some other reasons I came up with are time of day, random, entertainment … You probably could do it with script’s also. You’re giving me ideas. Thanks.

Edited: one other thing. This system auto sends the parameters as list. So in the calling script, don’t use the curly braces in the open command. e.g.

set f to choose file
tell application "sodTest"
	launch
	open f -- no braces sometimes
end tell

gl,
kel

Hi treed,

Here’s a better example for what you’re doing:

on open params
	set f to item 1 of params
	set i to item 2 of params
	if i is 1 then
		my Handler1(f)
	else if i is 2 then
		my Handler2(f)
	end if
	quit
	return
end open

on Handler1(f)
	beep 1
	-- do something with f
	return
end Handler1

on Handler2(f)
	beep 2
	-- do something with f
	return
end Handler2

Here’s the calling script:

set f to choose file

tell application "sodTest"
	launch
	open {f, 2}
end tell

gl,
kel

I’m quite sure that before, if you send a single item list, then it used to just send that list. I think now, if it’s a single item list then it sends a list of list. Need to check that out.

Edited: almost had a better example, but it doesn’t want to work:

property x : 0

set x to x + 1

on open params
	set f to item 1 of params
	set i to item 2 of params
	if i is 1 then
		my Handler1(f)
	else if i is 2 then
		my Handler2(f)
	end if
	return return
end open

on Handler1(f)
	beep 1
	-- do something with f
	return x
end Handler1

on Handler2(f)
	beep 2
	-- do something with f
	return x
end Handler2

The other script:

set f to choose file

tell application "sodTest"
	launch
	open {f, 2}
end tell

Interesting stuff.

gl,
kel

Oops, it must be the return return instead of result.:roll eyes:

If you figure out the other way, then a reply would be welcome with regards to the code.

gl,
kel

I appreciate all the advice, but after a bunch of testing and experimentation, I scrapped the idea of a helper app and went with a different technique that is working well.