Guest User

Untitled

a guest
Apr 25th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # copied from one of the well known/talented OSX developers who posted this simple snippet somewhere, since the
  3. # uti/filemap situation is quite confusing on 10.6.
  4. # there are other solutions, even in python, that have been done using graphviz to create a huge graph/network
  5. # of the relationships (can get rather large if you have >100apps). And, there are other solutions like
  6. # setting an application's affinity (code is on github by another great developer),
  7. # and a 10.6 service. I would think that these are going to get more complex, even becoming a niche industry for
  8. # someone to make $10 via registration off of at some point, since the new UTI system has some potential (using magic vs file suffix, etc)
  9. # </rant off>
  10.  
  11. import plistlib
  12.  
  13. thePath = '/System/Library/CoreServices/CoreTypes.bundle/Contents/Info.plist'
  14.  
  15. thePlist = plistlib.readPlist(thePath)
  16.  
  17. theDocumentTypes = thePlist['UTExportedTypeDeclarations']
  18.  
  19. theNames = {}
  20. theIndex =
  21. for theDocumentType in theDocumentTypes:
  22. theNames[theDocumentType['UTTypeIdentifier']] = 'UT%d' % theIndex
  23. theIndex += 1
  24.  
  25. print 'digraph G {'
  26.  
  27. for theDocumentType in theDocumentTypes:
  28. theType = theDocumentType['UTTypeIdentifier']
  29. theName = theNames[theType]
  30.  
  31. print '\t%s [label="%s"];' % (theName, theType)
  32.  
  33. if theDocumentType.has_key('UTTypeConformsTo'):
  34. if type(theDocumentType['UTTypeConformsTo']) == type(''):
  35. theDocumentType['UTTypeConformsTo'] = [theDocumentType['UTTypeConformsTo']]
  36.  
  37. for theConformTo in theDocumentType['UTTypeConformsTo']:
  38. theConformToName = theNames[theConformTo]
  39. print '\t%s -> %s;' % (theName, theConformToName)
  40.  
  41. print '}'
Add Comment
Please, Sign In to add comment