I'm trying to mod a python script that reads the OS X Dock plist. I've never seen python code before this and I can't seem to figure out if I'm encountering a formatting error or a syntax error or both...
Here is the original code snippet, which returns a formatted list of items in the Dock;
# since we are only reading the plist, make a copy before converting it to be read os.system('cp '+plist_path+' /tmp/com.patternbuffer.dockutil.tmp.plist') pl = plistFromPath('/tmp/com.patternbuffer.dockutil.tmp.plist') # print a tab separated line for each item in the plist # for each section for section in ['persistent-apps', 'persistent-others']: # for item in section for item in pl[section]: try: # join and print relevant data into a string separated by tabs print '\t'.join((item['tile-data']['file-label'], item['tile-data']['file-data']['_CFURLString'], section, plist_path)) except: pass # clean up temp file try: os.remove('/tmp/com.patternbuffer.dockutil.tmp.plist') except: pass
This works but does not include an entry for Dashboard, Yes, I know Dashboard does not have a standard entry in the plist, but does have the placeholder label 'dashboard-tile'. pl is an array of strings and print outputs a formatted string of values.
Can anybody show me how to test for the string 'dashboard-tile' and then print 'Dashboard' so it will be included in the list of items returned using the above code? It will always be be in 'persistent-apps' and should be in one of the strings in pl. It may not always be the first item (after the Finder).