Restart Application

Yes, I know it already happened. But let me suggest my version for restarting active applications. If there is a better option, then I will only be glad to see it here.


tell application "System Events" to set appNames to name of every application process
set currentApplicationName to name of current application

set appName to (choose from list appNames)
if appName is false then return
set appName to item 1 of appName
if appName is currentApplicationName then return

tell application appName to quit

tell application "System Events"
	repeat while appName is in (name of application processes)
		delay 0.2
	end repeat
end tell

try
	tell application appName to launch
on error
	try
		tell application appName to activate
	end try
end try

tell current application to activate