I have a machine on which I do not want finder to run, so initially I made it unexecutable:
sudo chmod -R a-x /System/Library/CoreServices/Finder.app
But then realised that launchd was still trying to launch finder multiple times every second, resulting in colossal log files consisiting of millions of lines of:
com.apple.launchd.peruser.502[109] (com.apple.Finder[93799]) <Error>: posix_spawn("/System/Library/CoreServices/Finder.app/Contents/MacOS/Finder", ...): Permission denied
com.apple.launchd.peruser.502[109] (com.apple.Finder[93799]) <Warning>: Exited with exit code: 1
So I edited /System/Library/LaunchAgents/com.apple.Finder.plist
so that it would not launch anymore. The problem I have now is forcing launchd to reload the plist, and therefore stop trying to launch finder. However, I cannot restart the machine.
I have tried using launchctl to both remove and unload the process but that doesn't appear to work:
$ sudo launchctl unload -w /System/Library/LaunchAgents/com.apple.Finder.plist
launchctl: Error unloading: com.apple.Finder
$ sudo launchctl remove com.apple.Finder
launchctl remove error: No such process
Is there anyway I can stop launchd continuously trying to load finder without restarting the machine?
Finder is a LaunchAgent, not a LaunchDaemon, which means it's loaded as part of your login session. Either use
launchctl unload
withoutsudo
, or just log out & back in.Your log shows that Finder is being run for user 502, but you are running
launchctl
withsudo
, and root isn't running a Finder. Try thelaunchctl unload
withoutsudo
.As Gordon said, you need to execute your
launchctl unload ...
command in the same mach bootstrap context of the user. launchctl itself has a facility to do this via bsexec, you just need to provide it a PID of any process running in that user context, Finder isn't running so pick a different one. The user-relative root process isloginwindow console
, so this makes the most sense:replace
yourusername
with the username you're affecting and voila.System
Mac OS X, version: 10.6.8 (Snow Leopard)
Task
I wanted to prohibit, mostly the initial auto-starting but also, the automatic re-launching of the Finder (as a "simple" fix for decrypting encrypted disks) before the Finder would try (and fail) to load (and in that process discard) it's old (preferences'd) list of previous open locations..
Reliability
I seldom restart my computer (and haven't had any much crashes with the Finder) so
i haven't gotten to see the effect of this configuration (that feels more like a hack) that many times.
I also see now that i haven't backed my original up so i cannot see exactly what changes i've made.
Procedure
Anyhow, it seems that the re-launching is removed (as expected) by setting
<key>KeepAlive</key>
in the Finder'slaunchctl
(1)/launchd
(8) property list to<false/>
;But, setting the
<key>RunAtLoad</key>
(again, to<false/>
) seems to have no effect (on the Finder as it probably is started ~hardcoded”).On a side-note I can say that creating a LaunchAgent - for/with any other regular application - with
<key>RunAtLoad</key>
set to<true/>
works great if you, like I, have an app (share-service) that crashes often.References
launchd.plist
(5)man
ual page at Apple's technical note #2083 on the subject (2011-12-28: "Last updated: 2007-11-05")And a little utility
If i may recommend a graphical application for these
LaunchAgents
/LaunchDaemons
configuring tasks i'd like to promote (without any affiliation, other than developing nationality) Lingon (note the different (Snow) Leopard and Lion versions).Finally
Sorry for the long post on this rather trivial issue.
Hope most of this is still true in version 10.7 Lion as well. Though the Finder's behaviour could be better (somehow, suggestivly not totaly discarding unreacahble locations) in line with "Resume" Lion feature along with "Auto Save"..
Now i just still have one other little mac thing (file sizes) to comment on at unix.stackexchange).
The error message given in some of the comments:
shows that
launchctl
is trying to open a file and failing. This could be due to permissions, but that seems unlikely, given the use ofsudo -u
. Much more likely is something related to theO_EXLOCK
flag. Presumablylaunchd
locks the database when starting a job, perhaps to check if the job is disabled, and it's retrying the job so frequently that the database file is locked most of the time.Running a loop that continually tries to unload the job should eventually get in when
launchd
doesn't have the file locked:I know that unloading a job from
ssh
normally works, because I've done it many times, so I think the problem must be due to the frequency of the failure/reload cycle.I get what you're trying to do, but you're going about it entirely the wrong way.
Use the Parental Controls to set up a restricted account. Set it to use the Simple Finder.