How to quit AND relaunch Finder in same script?

I’ve been trying to write a simple script that goes:

tell application “Finder” to quit
tell application “Finder” to launch

The script quits Finder okay, but then doesn’t launch it again. A script with just the 2nd line in it alone will happily launch Finder once it’s been quit, but I can’t get both lines to work consecutively in the same script - aragh…

So what am I doing wrong? Do scripts drop themselves out after Finder is quit, or is there maybe some syntax I’m missing here to get the launch to happen after the quit?

  • padmavyuha

For some reason, you’ve got to give the Finder a little time to totally disengage before trying to launch it again. Try this code:

Jon

I would even try the following


try
tell application "Finder" to quit
end try
delay 2
tell application "Finder" to activate

In some cases, the Finder may quit without returning the necessary AppleEvents, and causing Applescrip’s to raise an error ‘Invalid Connexion’

This will relaunch the finder, but it doesn’t start it up in the same state you left it.

do shell script "kill -1 `ps aucx | grep Finder | awk '{print $2}'` "

In the end, I found that:

try
     tell application "Finder" to quit
end try
delay 2
tell application "Finder" to activate

works the best - it’ll work from e.g. YoupiKey (or iKey as it’s now known) but it won’t work from e.g. Big Cat as a CMM-run script, presumably because quitting the Finder shuts down the CMM scripting capability. When I say ‘work’ I mean both quit AND relaunch Finder - just quitting it is no problem!

Thanks for the various responses…