PDA

View Full Version : postinstall script packagemaker




BollywooD
Oct 18, 2009, 06:17 AM
how do I delete a key in a plist file, in a postinstall script?

I have tried:
#!/bin/sh

defaults delete $HOME/Library/Preferences/com.apple.Safari myKeyToDelete


the script deletes the entire plist file though, not the key?

what am I doing wrong.



Guiyon
Oct 18, 2009, 12:00 PM
IIRC, defaults does not use the path to the plist file, instead it uses the reverse-DN of the domain you want to alter. In this case it will be com.apple.Safari

So, according to the man page, you would want to call:
/usr/bin/defaults delete com.apple.Safari <KeyName>

BollywooD
Oct 18, 2009, 02:50 PM
IIRC, defaults does not use the path to the plist file, instead it uses the reverse-DN of the domain you want to alter. In this case it will be com.apple.Safari

So, according to the man page, you would want to call:
/usr/bin/defaults delete com.apple.Safari <KeyName>

I tried this:

#!/bin/sh

/usr/bin/defaults delete myKeyToDelete


which generates an error in the installer, and doesn't delete the key.
and this one:

#!/bin/sh

MY_UNUSED_KEY="com.apple.Safari myKeyToDelete"
if [ -d "MY_UNUSED_KEY" ]; then
echo "Removing unused preferences"
/usr/bin/defaults delete "MY_UNUSED_KEY"
fi

which doesnt generate an error, but also doesnt delete the key?


this shouldnt be that difficult....

Guiyon
Oct 18, 2009, 05:15 PM
Reread the command I posted. You forgot to specify the domain you wanted to remove the key from.

BollywooD
Oct 18, 2009, 05:47 PM
I tried this too:

/usr/bin/defaults delete ~/Library/Preferences/com.apple.Safari myKeyToDelete

this deletes the entire plist file....


stupid PackageMaker!?...

BollywooD
Oct 18, 2009, 06:13 PM
I also posted the question to the installer-dev mailing lists, and found the solution to be:

su $USER -c "defaults delete com.apple.Safari myKeyToDelete"

:D

Guiyon
Oct 18, 2009, 06:29 PM
I also posted the question to the installer-dev mailing lists, and found the solution to be:

su $USER -c "defaults delete com.apple.Safari myKeyToDelete"

:D

Which is the exact command I posted.

chown33
Oct 18, 2009, 08:07 PM
#!/bin/sh

MY_UNUSED_KEY="com.apple.Safari myKeyToDelete"
if [ -d "MY_UNUSED_KEY" ]; then
echo "Removing unused preferences"
/usr/bin/defaults delete "MY_UNUSED_KEY"
fi

which doesnt generate an error, but also doesnt delete the key?

this shouldnt be that difficult....

That shell script doesn't work because you're using the literal string "MY_UNUSED_KEY", rather than expanding the value of the shell variable. To expand the shell variable, you should use "$MY_UNUSED_KEY".

Also, your defaults delete ... line is wrong for a second reason: you're quoting the expanded shell variable. So even if you had this:

/usr/bin/defaults delete "$MY_UNUSED_KEY"

It would still be wrong, because it would expand to this:

/usr/bin/defaults delete "com.apple.Safari myKeyToDelete"



It pays to actually understand the tools you're working with, whether that's the defaults command or the syntax of shell variables. RTFM.

It also pays to read replies before posting other failed attempts. RTFR.

BollywooD
Oct 18, 2009, 09:59 PM
It pays to actually understand the tools you're working with, whether that's the defaults command or the syntax of shell variables. RTFM.

Thanks for the crash course, Im only just gettng to grips with Obj-C, and now I need to learn another language....
:)