Benches macOS

9

launchd.plist problem

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

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...

9 replies

Sign in or join Beachball Help to reply.

  1. 0

    Neville Hillyer

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    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.

  2. 0

    Camelot

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    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.

  3. 0

    Nem0Nada

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    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.

  4. 0

    Neville Hillyer

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    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

  5. 0

    Nem0Nada

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    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.

  6. 0

    Jeffrey Jones2

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    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).

  7. 0

    Nem0Nada

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Clever! Instead of trying to find the path then run a script on it, you're letting the plist tell 'defaults' just to do it. Looks like it should work. I'll test it and get back to you.

    Thank you very much!

  8. 0

    Camelot

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Interesting - it certainly sounds like you have it set right.

    I admit I've never used a WatchPath with a relative directory, so I'm only working on speculation as to how I'd expect it to work.

  9. 0

    Neville Hillyer

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Sorry - I forgot to mention that this works on my G4 with OS X 10.5.8 without anything unreasonable showing on Console.