#!/usr/bin/perl ################################################################################ # Copyright (c) 2011 University of Utah Student Computing Labs. # All Rights Reserved. # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose and without fee is hereby granted, # provided that the above copyright notice appears in all copies and # that both that copyright notice and this permission notice appear # in supporting documentation, and that the name of The University # of Utah not be used in advertising or publicity pertaining to # distribution of the software without specific, written prior # permission. This software is supplied as is without expressed or # implied warranties of any kind. ################################################################################ use Foundation; use lib "/usr/local/lib/"; require "perlplist.pl"; usage() if ( $#ARGV < 2 ); my $filename = shift @ARGV; my $dict; if ( -e $filename ) { $dict = loadDefaults( $filename ); } else { print "The file $filename does not exist, creating a new file.\n"; $dict = NSMutableDictionary->dictionary(); } setPlistObjectForce( $dict, \@ARGV ); printObject ($dict); saveDefaults( $dict, $filename ); ############################################################################### sub usage{ print < [ ...] This script will modify a plist file according to the container path specified and the datatype specified. It can only set one value at a time (but can create an entire path all at once if it is missing). Container flags: -d = dictionary -a = array If an array index is specified that does not exist, it will create indexes with blank values that are the same datatype as the last value. Indexes are zero based. Specifying a key or index that already exists will overwrite any existing values without warning! Datatype flags: -s = string -i = integer -f = float -b = boolean -t = date Examples: $0 /path/to/file.plist -d ABC -s "Stringy" ABC Stringy $0 /path/to/file.plist -d List -a 3 -s "I'm a string" List I'm a string $0 /path/to/file.plist -d Dates -d "A good day" -t 121766400 Dates A good day 1973-11-10T08:00:00Z $0 /path/to/file.plist -d true -b 0 true EOF exit; }