diff --git a/usr/local/bin/print_plist_entry.py b/usr/local/bin/print_plist_entry.py index da97a16..0737a2a 100755 --- a/usr/local/bin/print_plist_entry.py +++ b/usr/local/bin/print_plist_entry.py @@ -103,13 +103,19 @@ try: with open( plist, 'rb' ) as fp: content = plistlib.load( fp ) except: - print( "\nError: plist is not a XML file!\n" ) + print( "\nError: not able to load plist!\n" ) sys.exit( 1 ) -try: - print( key + ":", content[ key ] ) -except: - print( "\nError: key not found!\n" ) - sys.exit( 1 ) +# net to be able to get values of keys and subkeys +def _finditem(obj, key): + if key in obj: return obj[key] + for k, v in obj.items(): + if isinstance(v,dict): + item = _finditem(v, key) + if item is not None: + return item -sys.exit( 0 ) +# find key and print value (recursively) +print( key + ":", _finditem( content, key ) ) + +sys.exit( 0 ) \ No newline at end of file