this seems to work, but is it the correct way of doing it?
#!/bin/sh
#find all users for arg in `ls /Users` do
#remove unused preference for user, if it exists if [ $arg != 'Shared' ]; then /usr/bin/su $arg -c "/usr/bin/defaults delete com.apple.Safari myKeyToDelete" exit 0 fi done
Russell
On 19/10/2009, at 12:12 PM, Bill Coderre wrote: su means "Simulate Users"
You can write a loop that looks for directories in /Users (ignoring . and .. and Shared) and those directories probably correspond to users on the system.
For instance, on my mac, /Users/test/ and /Users/jen/ correspond to the users test and jen.
So then you could do su test -c "defaults delete com.apple.Safari myKeyToDelete" su jen -c "defaults delete com.apple.Safari myKeyToDelete"
Now, the writing of loops, testing of existence, etc. This is something I would do in perl, but it can certainly be done in csh. It is precisely the kind of thing people did in csh until perl came along....
You can find out how to do shell programming online, and might get some info from man csh
(But honestly, I doubt you will get much from the man page. I hate that man page.) I don't have a favorite shell programming book. I'd probably look through the various O'Reilly books and find one that looked good.
Perl, my pal Nat Torkington wrote The Perl Cookbook -- I'd prefer not to think of how long ago that was -- it's almost good enough on its own. (There's also Perl Programming to cover the more basic concepts. When something's too basic to be covered in the Cookbook, I can usually find it online at http://perldoc.perl.org/ ) On Oct 18, 2009, at 5:30 PM, Russell Gray wrote: exit 0
produces the desired result.
You got me interested in iterating through all the users, and removing keys from all accounts. where do I start.
I have done a: man id man su
but the documentation isn't the greatest.
Russell
On 19/10/2009, at 11:23 AM, Bill Coderre wrote: Note that in general, if you are not expecting your command to error, it's better not to ignore errors.
But in this case, it might not be a big deal to do so, so I'll tell you how to ignore errors.
First, try merely adding the following to the end of the script. It might be enough. exit 0
You can see how to add some junk to the end of the command to cause output to be funneled to /dev/null, the unix "bit bucket."
I write my installer preflights and postflights in perl, because there are fewer quote mark hassles, but the result is that the syntax is a bit different: my $IGNORE = `/usr/bin/su $USER -c "/usr/bin/defaults delete com.apple.Safari myKeyToDelete" 2>&1`;
What this does it send any errors to stdout, and then stdout is shoved into the variable $IGNORE, which I then ignore.
And yeah, I tend to use the full paths to the commands, to avoid any possibility that I'll end up running someone's private copy that does Different Stuff.
If you don't want to ignore errors, learn how to use defaults: man defaults defaults help
On Oct 18, 2009, at 4:36 PM, Russell Gray wrote: I have one more related question.
How do I check for the existence of the key - as the installer throws an error if the key does not exist.
Russell On 19/10/2009, at 10:33 AM, Bill Coderre wrote: Note well that this ONLY affects the current user. If the machine has more than one user, their prefs won't be affected!
You can iterate through /Users and get all those users, and then for extra credit see if the logged-in user's home is in /Users, and if not, do them as well. (The logged in user might have a home directory on the network somewhere.)
That's what iLife does. Works well enough, apparently.
On Oct 18, 2009, at 4:10 PM, Russell Gray wrote: Perfect!
many thanks to everyone for the help!
Russell On 19/10/2009, at 10:06 AM, Bill Coderre wrote: You probably have to wrap the "defaults" part of the command in quotes: su $USER -c "defaults delete com.apple.Safari myKeyToDelete"
On Oct 18, 2009, at 3:44 PM, Russell Gray wrote: the installer throws an error, and the key is left untouched.... On 19/10/2009, at 9:09 AM, Iceberg-Dev wrote: Does this work?
su $USER -c defaults delete com.apple.Safari myKeyToDelete
On Oct 18, 2009, at 11:40 PM, Russell Gray wrote:
the script works perfectly, when run directly through Terminal - just not as a postinstall script in PackageMaker?
|