开发者

Trying to write Python script to remove duplicate fonts Mac OSX

I am trying to write a utility to check through the fonts on OSX and remove duplicates - so far I've had su开发者_运维问答ccess iterating through the folder structure and writing out an xml file containing fonts and paths. The drawback is that this doesn't find duplicates as the same font can be installed twice in different locations but with a different file name; font family information is internal to the font file.

I have found this: List of installed fonts OS X / C

import Cocoa
manager = Cocoa.NSFontManager.sharedFontManager()
font_families = list(manager.availableFontFamilies()) 

Which uses PyObjC to list installed fonts. This looks like a possible solution but I'm not a heavy weight coder and know nothing about PyObjC! I did have a play around in a terminal with dir(manager)and dir(NSFontManager)to see if I could find a method that returned the file paths of installed fonts but to no avail.

Any help gratefully received.

Best wishes

//Simon


Install the fonttools package and take a look at this blog post. There's a script there that gives the font name of its first argument and I'm sure you could adapt it to your use case.


Thanks once again for the replies - I just wanted to update this in the hope it helps. I'm looking at fontTools now, but admit I am having trouble finding documentation. According to the developer's page there are libraries to handle other fonts apart from ttf, but I'm still looking with little success just yet!

In the mean time, I did turn up this page on Using Apple Font tools, which seems get half way to what I need - ie listing installed fonts and locations. It looks like the ftxinstalledfonts command will accept a pipe so in theory I could pipe the output to my existing python script that builds an xml database. I'm assuming I can do this by calling ftxinstalledfonts via the sys module but am not clear as to how to get the output... I'll go and plunder the python docs but if there's no luck and someone has 10 secs to give a pointer I'd be grateful.

As a quick aside, the Font Geek site above has some very useful stuff about TTX as well.

Best wishes

//Simon

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜