Sunday, December 13, 2009

How to import Mac OS X's icons in Visio

You certainly know the program Visio (Microsoft Office) that allows to make beautiful diagrams ... the only small snag, Visio's icons are particularly ugly... Therefore let me show you two techniques to import the beautiful Snow Leopard icons in your Visio.

Method: by hand

Select the application whose you want import the icon (with the famous Apple + C), then open the Preview application and choose "New from clipboard"
you will just have to save it as and choose the PNG format. You can now import your image into Visio.

Second method: using a script

The previous method let you to extract only an icon at a time, if you want to retrieve all the icons of Mac OS X, you can use the following python script:


/bin/python

import os
import re

text = "0000"
out = "~/Pictures/"

stdout_handle = os.popen ( "find / -name *. icns", "r")
while (text !=""):
stdout_handle.readline text = ()
regnamefile = re.compile ( '\/([^//]*)\. icns')
namefile = regnamefile.findall (text) [0]
Reglin = re.compile ( '(\/ .*\. icns)')
line = regline.findall (text) [0]
os.system ( "sips-s format png"+line+"-out"+out+namefile+".png")

Beware the indentation : it is the python ... ;-) The script first look for all icns file (the format of the icons of Mac OS X ;-) ;-)), then apply a transformation using the application sips available on Mac OS X. All files in PNG format will be created in your pictures folder ...

That ;-) I hope you will make beautiful patterns after that.