How to get an applet to relaunch itself instead of quitting?

How to get an applet to relaunch itself instead of just quitting?

Edit, Sep 11, 2016 ” [SOLVED]

OK, I finally pieced together how to make all this work:

set nameOfThisApp to name of me
tell application "System Events" to set the frontmost of process nameOfThisApp to true
display dialog "Ready? (cancel to abort infinite loop)"

do shell script "osascript -e '

	tell application \"" & nameOfThisApp & "\" to quit
	delay 0.5 -- (give it time to quit)
	tell application \"" & nameOfThisApp & "\" to activate
' &> /dev/null &" -- [end shell script]

At first I was thinking that every line had to be with its own “osascript -e” (ugly!), but after I disabused myself of that notion, I then thought that I must have all the AppleScript code on one, unintelligible line, but then I realized that it would accept carriage returns within one set of the -e 's single-quotes argument, making for very legible AppleScript!

I don’t think there’s a way to incorporate quoted form of into it, because of the AppleScript code already being within single-quotes (osascript -e ’ [AppleScript] '), so I’m stuck with all the awkward escaped double-quotes.

memo: I also found the solution in my post #2 to make shell multi-commands in one line separated with semicolons all covered by the backgrounder (&> /dev/null &): Enclose all the multi-commands within parentheses, e.g.,

do shell script "(sleep 2; osascript -e 'tell application \"\" to quit') &> /dev/null &"

(original post, Aug 30, 2016):

How to get an applet to relaunch itself instead of just quitting?

(This would make effective my script’s adding a LSUIElement key of string value “1” to its own info.plist, and make it run as a faceless background app upon relaunch… And no, in this case the adding this key to a live info.plist doesn’t get overwritten upon quit.)

I’m trying to avoid having a second script applet to relaunch the main applet, as usually is suggested elsewhere here.

I’ve found a launchctl command that would do it:

do shell script "launchctl submit -l jobLabel ~/Desktop/"
tell me to quit

…but it also makes launchd keep the app persistent when quit or crashed, so upon relaunch I’d then have to issue a:

do shell script "launchctl remove jobLabel"

…but that also quits the relaunched app, defeating my purpose. I can’t find on the man page a launchctl subcommand that does a remove of the launchd job while leaving the app running, so I’m asking if anyone knows a shell command that simply relaunches an app.

AppleScript: 2.1.2
Browser: Firefox 45.0.2
Operating System: Mac OS X (10.6.8)

OK, why doesn’t this work, quitting itself? (It works to quit other apps.)

do shell script "sleep 2; osascript -e 'tell application \"\" to quit' &> /dev/null &"

“ This applet saved as “” (“Stay Open”).
“ If I leave out the backgrounder suffix (“&> /dev/null &”), the GUI just hangs and must be force-quit.

The backgrounder suffix doesn’t include any prior commands separated by semicolons on a single-line, multi-command shell script, and so doesn’t release the shell script for further AppleScript processing until the last actual command it appends. Which means that I couldn’t do a shell script which sleeps some time to allow quitting within my main script applet before it issues a command to activate my main script applet again. I’ve tried several combinations & permutations (e.g., appending the backgrounder suffix separately to each prior command on the line, writing separate shell scrips with each having the backgrounder suffix), but I can’t figure out a syntax that would send to background/release control back to my script applet both the time delay and the activate command.

[SOLVED] See first post.