postinstall script packagemaker

Discussion in 'Mac Programming' started by BollywooD, Oct 18, 2009.

  1. macrumors 6502

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
    #1
    how do I delete a key in a plist file, in a postinstall script?

    I have tried:
    Code:
    #!/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.
     
  2. macrumors 6502a

    Joined:
    Mar 19, 2008
    Location:
    North Shore, MA
    #2
    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:
    Code:
    /usr/bin/defaults delete com.apple.Safari <KeyName>
     
  3. thread starter macrumors 6502

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
    #3
    I tried this:

    Code:
    #!/bin/sh
    
    /usr/bin/defaults delete myKeyToDelete
    
    which generates an error in the installer, and doesn't delete the key.
    and this one:

    Code:
    #!/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....
     
  4. macrumors 6502a

    Joined:
    Mar 19, 2008
    Location:
    North Shore, MA
    #4
    Reread the command I posted. You forgot to specify the domain you wanted to remove the key from.
     
  5. thread starter macrumors 6502

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
    #5
    I tried this too:

    Code:
    /usr/bin/defaults delete ~/Library/Preferences/com.apple.Safari myKeyToDelete
    this deletes the entire plist file....


    stupid PackageMaker!?...
     
  6. thread starter macrumors 6502

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
    #6
    I also posted the question to the installer-dev mailing lists, and found the solution to be:

    Code:
    su $USER -c "defaults delete com.apple.Safari myKeyToDelete"
    :D
     
  7. macrumors 6502a

    Joined:
    Mar 19, 2008
    Location:
    North Shore, MA
    #7
    Which is the exact command I posted.
     
  8. macrumors 603

    Joined:
    Aug 9, 2009
    #8
    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:

    Code:
    /usr/bin/defaults delete "$MY_UNUSED_KEY"
    
    It would still be wrong, because it would expand to this:

    Code:
    /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.
     
  9. thread starter macrumors 6502

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
    #9
    Thanks for the crash course, Im only just gettng to grips with Obj-C, and now I need to learn another language....
    :)
     

Share This Page