I have a plist setup with ‘WatchPaths’ set to ~/Library/Preferences. When it runs, I get 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_core_logic.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).
I have a plist setup with ‘WatchPaths’ set to ~/Library/Preferences. When it runs, I get 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?[/QUOTE]
Nope. File an enhancement request with Apple.
[QUOTE][
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…[/p][/QUOTE]
Best you can do currently is run on a set schedule (every 5 mins, every 15 mins, whatever, check the value, and reset it if needed.) Or manage it ‘often’, realizing that if the user changes it, it won’t be reset until the next login.
It’s not a super elegant solution but you could write a loginhook that unloads the daemon, rewrites the plist, and then reloads the daemon. This would be pretty easy since a loginhook runs as root and the $1 parameter is the username.
Apple has a technote for creating a loginhook here: [url]http://support.apple.com/kb/HT2420[/url].
Another great resource is located here: [url]http://www.jochsner.dyndns.org/scripts/Scripts.html[/url]. Checkout the NHR package. It installs a nice loginhook system. One master script that runs all scripts in a folder. It also shows you how to get the user name and find the users home directory using dscl. Very nicely done.
Don’t write a login hook if you actually want your code to work in the future, and don’t expect launchd to expand tildes or provide a full login shell environment anytime soon. There are plenty of ways to determine the user’s name and build the correct path yourself.
don’t expect launchd to expand tildes or provide a full login shell environment anytime soon. There are plenty of ways to determine the user’s name and build the correct path yourself.
Comments are closed