Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

launchd.plist problem

Greetings;

This was originally posted under OS 10.5 - Installation and Setup and it was suggested that I re-post it here. Thank you for your time!

I have a plist setup with 'WatchPaths' set to ~/Library/Preferences. When it runs, the message "~/Library/Preferences" cannot be found. If I put the WatchPaths to (for example) "/Users/administrator/Library/Preferences" then everything works fine.

How can I get the plist to recoginize the '~' for currently logged on user? Or is there another way to designate the logged on user's directory w/o spelling it out for each users?

I've tried setting 'WorkingDirectory' to $HOME but that generates the following: "Bug: launchd corelogic.c:3119 (23923):2: chdir(j->workingdir) != -1"

Also tried using the 'EnvironmentVariables' key but couldn't come up w/a way that that would work either?

The goal here is to monitor the screensaver settings and set the idleTime to a certain value, even if the user changes it. I can use WGM to lock the askForPassword value but there doesn't seem to be anyway to lock the idleTime (which would solve the whole problem).

Suggestions???? Please...

All, Mac OS X (10.4.11)

Posted on Apr 5, 2010 4:27 PM

Reply
9 replies

Apr 5, 2010 4:54 PM in response to Nem0Nada

The big question is where you're putting this .plist.

If you want the .plist to act upon a specific user's directory, then it should be stored in /Library/LaunchAgents. That way it fires off when the user logs in and should know the user's environment.

If you're putting the script in LaunchDaemons then this is bound to fail since there's no specific user account under which the task is running.

Apr 5, 2010 10:30 PM in response to Camelot

It is in /Library/LaunchAgents and triggers beautifully when the user logs in.

The "catch" is the 'WatchPaths' parameter. I need the agent to watch the "~/Library/Preferences/ByHost" path but it doesn't understand the '~' character at the beginning. The 'envar' plist is running on has PWD = '/'. The other variables are there, e.g. $USER, $HOME but the plist doesn't recognize them or at least I can't get it to recognize them.

Apr 6, 2010 8:16 AM in response to Camelot

I don't know the answer to your question.

How many users do you have? If it is a fixed low number you could consider watching all directories.

Am I mistaken or should you be watching the following?

~/Library/Preferences/ByHost

How secure does this need to be? Is it worth considering simply locking the following for each user?

~/Library/Preferences/ByHost/com.apple.screensaver.############.plist

Apr 6, 2010 6:39 PM in response to Neville Hillyer

Yes, I'm trying to watch

~/Library/Preferences/ByHost

but that comes back as no such path.

Watching all users would work, just more complicated. Would have to check all users at logon, get path if there's a new one then write to the plist. Seems like it shouldn't be that hard...

I thought about locking the file or using WGM to just remove the choice from their preferences but the only requirement is 15 min and must use password. I don't care what screensaver they use. Didn't want to take everything away from them if I didn't need to.

Apr 7, 2010 8:21 AM in response to Nem0Nada

Of course ~/Library/Preferences/ByHost does not exist. The ~ is a metacharacter for a shell -- an instruction to the shell -- telling it to substitute the home directory of the owner of the shell instance. Outside of a shell context, the tilde has no meaning other than the character tilde.

The concept of "currently logged in user" is vague, since there can be more than one or none. A shell inherits an environment for the process that invokes it. I don't know how your launchd process would get an environment from an external process (in this case a "logged in user session).

Apr 7, 2010 9:30 AM in response to Nem0Nada

I agree that my earlier suggestion is too complex if there is not a small fixed number of users.

I see you want this for Leopard although your details only show Tiger.

I have only been able to get absolute watch paths to work and I did not find it easy to Google relative path for launch agents/plist.

However I think I have found a solution which should work for you:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" " http://www.apple.com/DTDs/PropertyList-1.0.dtd ">
<plist version="1.0">
<dict>
<key>Label</key>
<string>screen-saver.idle-time</string>
<key>ProgramArguments</key>
<array>
<string>defaults</string>
<string>write</string>
<string>ByHost/com.apple.screensaver.MAC-or-UUID</string>
<string>idleTime</string>
<string>-int</string>
<string>900</string>
</array>
<key>StartInterval</key>
<integer>60</integer>
</dict>
</plist>


This refreshes the active users' 900 second idle time every 60 seconds provided System Preferences have been closed. You can reduce the 60 seconds for testing but don't go below 11 seconds or automatic spawn throttling will kick in. Replace MAC-or-UUID with whatever MAC address or UUID number the OS is using for other items in ByHost. Either use a text editor to put the above in a file at /Library/LaunchAgents/screen-saver.idle-time.plist and then resolve its permissions or use Lingon. You can change screen-saver.idle-time to anything you wish but it is best to use the same for both file name and plist Label.

launchd.plist problem

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.