Edit: Well now it seems to just work. I have no idea what's going on lol.

Can someone tell me what's going on here?

tell application "Terminal"
    do script "killall Finder"
    tell application "Finder"
        repeat while running
        end repeat
    end tell

    close window 1
end tell

tell application "Finder"
    repeat while not running
    end repeat

end tell

Finder got an error: Application isn’t running." number -600

is what I get. If I comment out

repeat while not running
end repeat

I don't get the error, but if I leave that in and comment out


Instead, I also don't get an error. So apparently they interact with each other to cause an error somehow. If I add a delay I can avoid the problem, but I wan't to know why what I have causes an error. I have OS X 10.9.4.

  • What is it that you are trying to accomplish with this script? – Alistair McMillan Aug 8 '14 at 23:08
  • Well I guess I'm trying to restart Finder and then put it back in focus. I made this to show the error I'm getting in a simple form. – Mason Aug 8 '14 at 23:15
  • I'd love to help you with this, unfortunately the code works fine on my Macs. :) – Alistair McMillan Aug 9 '14 at 0:50
  • Looking at the event log I see that somehow the activate command is getting called over and over again like it's in the loop. – Mason Aug 9 '14 at 4:22
  • what the hell, when I place 'activate' inside the loop, it gets called once, but when it's out of the loop, it gets called over and over again. – Mason Aug 9 '14 at 4:24

You're killing Finder from Terminal, then telling Finder to 'repeat while running'... you just killed it, it's not running. You're also not doing anything in the repeat while, just telling the script to spin its wheels at full revs. I really have no clue what you're trying to achieve from this.

If you just want to restart the Finder [Opt/right clicking it in the dock is one easy way] then try..

tell application "Finder" to quit
delay 3
set test to 0
repeat while test = 0
    log test
    tell application "System Events" to set test to count (every process whose name is "Finder")
    delay 2
    --//we do this even if active because it doesn't naturally come to front
        tell application "Finder" to activate
    end try
    if (test > 0) then exit repeat
end repeat
  • lol I didn't know you could quit Finder via AppleScript. Okay, what the first repeat while loop was doing was delaying the program. Without that, the script goes faster than the computer can execute what it's being told to do. The loop makes sure killall has executed before the window is closed. The second loop was supposed to make sure Finder has finished relaunching so the activate command will work. – Mason Aug 9 '14 at 14:46
  • error: Application isn’t running." number -600 pretty much says what I said, you can't check it for running, because the process you are calling for the check... isn't running. You need System Events to monitor that. – Tetsujin Aug 9 '14 at 17:16
  • In the original program this occurred in, the repeat while running loop made it work. In this one it does nothing and is not needed. – Mason Aug 9 '14 at 20:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .