In my testing (which I did back in 10.6, so things may have changed - Iâll test again), if you try to load a QueueDirectories job that points to a non-existent directory path, the job disables itself and needs to be restarted explicitly.
Again, try my testbench script for yourself. Thatâs not what it does.
If I were going to do a launchd QD on a folder attached to a removable file system, Iâd make it a two-stage process: have one job that watches for the file system to mount (using the StartOnMount key) and loads the second job that watches the folder. That way youâre not depending on side effects to get main effects.
That is an excellent idea. Iâll try it.
Also, as an aside, QDs are annoyingly touchy. It took me forever to realize that QDs will not reactivate even if there are invisible files present. So, common fubar scenario: a QD watched folder gets opened in the Finder, a .DS_Store file is created, the QD script does not dispose of it: QD no longer fires. Argh.
Thatâs not what Iâm seeing. As I wrote in this report,
If you set QueueDirectories and launchd sees that the directories are not empty after the job runs, it considers that to be a failure and runs the job again after the ThrottleInterval expires. Therefore, if youâre trying to set up a repeating job that runs only when a given directory exists, you canât use QueueDirectories for that purpose.
bewst wrote:
Considering Iâm setting UserName=_news, I have to run it from there anyway. Iâm well aware of the permissions issues, thanks. đ
The UserName key is only applicable when you are running the job as root, meaning it must be run as a LaunchDaemon, not a LaunchAgent. Which, of course, I assume is what youâre doing. đ
That is what Iâm doing now, but of course I had to discover that the hard way. I find Appleâs documentation on launchd woefully inadequate. If it ever explicitly says that jobs in /Libraries/LaunchAgents are not run as root, I never saw it (no, saying that the job runs âon behalf of the userâ does not necessarily imply it will be run as that user).
bewst wrote:
twtwtw wrote:For tasks that only need to run periodically, leave launchd to decide when to start and stop them.
Itâs not entirely clear what you mean by that. Every plist file contains +some+ kind of specification (even if only implicit) about when jobs should be started or stopped.
Yes, but my point was that you should leave launchd to determine when those conditions are met.
I still donât understand the distinction youâre pointing at. I never try to tell launchd that the conditions for start/stop are or arenât met, and I wouldnât know how to do so. As far as I can tell, itâs okay to use the mechanisms that Apple describes in âman launchd.plist,â and thatâs all Iâm trying to do.
Iâve never had much success trying to co-opt a launchd trigger to do something it wasnât specifically designed to do, the way youâre trying to co-opt the QD key.
Well, the problem is that the documentation of these things and how they interoperate is so vague that itâs not at all clear exactly what they were specifically designed to do. The best Iâve been able to do is black-box testing to discover what to expect.
As best I can figure, launchd is simple-minded (designed to be robust and quick rather than smart and flexible) so it doesnât deal particularly well with novel approaches.
How to know if what Iâm doing is novel? Just try, I guess, and see if it works :-(
bewst wrote:
Itâs probably overly cute, but I am trying to prevent launchd from even launching a process for my job if it shouldnât run. QueueDirectories seems to do that.
Yeah, I figured; I frequently have that same kind of urge myself, and constantly have to fight against it. Meditate on the fact that youâre wasting of a heck of a lot of +human-scale+ time in an effort to save yourself a tidbit of +computer-scale+ resources that you simply will not ever miss. Or at least, if your machine is running so tight that launching a momentary process actually creates a noticeable disruption in +anything+, you need a new machine. Iâm a great fan of elegant code, yes, but I make sure it stops +well+ short of OCD.
Yeah, Iâll cop to being a little bit obsessive about battery life.