MacOS – Force relaunch of Finder from terminal into background

findermacosterminal

For some reason, Finder is no longer running and will not relaunch using conventional methods.

I can, however, get it running with the following command in the Terminal:

prompt$ open -g /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder &

Despite the fact that I'm ending the command with an ampersand and passing the -g flag to open, the resulting Finder opens attached to a completely new Terminal window that, when closed, causes the Finder application to also exit.

How can I relaunch the Finder from the Terminal, ensuring that it will run in the background without spawning a new shell?

Best Answer

The open command exits after it opens Finder. Even if it didn't, closing a shell would close background processes. You could try using disown:

/System/Library/CoreServices/Finder.app/Contents/MacOS/Finder & disown $!

Or launchctl submit:

launchctl submit -l my.finder /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder

launchctl remove my.finder removes the job.

Have you looked at log messages or crash reports? If you have tried to load or unload /System/Library/LaunchAgents/com.apple.Finder.plist, try removing entries for Finder in /var/db/launchd.db/com.apple.launchd{,.peruser.501}/overrides.plist.