Wednesday, March 20, 2013

Other Mac things I have learned

Show hidden files in any open / save dialog  

As a programmer there are times you need to create files that start with a '.' (period / dot) such as .bash_profile. But what happens when you want to open that file to edit it? The standard Open Dialog does not show hidden or system files.

Press Cmd+Shift+.  (that is the period) when the dialog is open to show all those bonus files.

Change file association

I wanted to open JPG files in Picasa instead of Preview.

Right click on a file and selecte "Get Info"
Change default application to open it with, then click the button [Change All]

Use XML_GREP to quickly pull data from XML files

There are times you are given an XML file and you want to quickly pull small pieces of information out of it. No need to write a full SAX or DOM parser to do that when you can use XML_GREP.

Sample of a record in the XML file
    <TITLE><![CDATA[Executive Report]]></TITLE>

Would show:
Executive Report

To grab multiple tag values:
xml_grep --text_only --cond 'TITLE' --cond 'TYPE' assetDataReport.xml

Would show:
Executive Report

Remove the --text_only parameter if you want to see the TITLE tag information too.

How to install XML_GREP

 Visit: and download latest version

  cd XML-Twig-3.42 (use version downloaded here in place of 3.42)
  perl Makefile.PL -y
  make test 
  sudo make install

Format XML file (pretty print)

Let's say you have an XML file that is all one one line or has no indenting and you want to pretty print it. You can use xmllint which is already installed on you Mac to do that. Here I am converting Sample Report.xml to newfile.xml where Sample Report.xml is the original unformatted file and newfile.xml is the indented pretty version of the file.

  xmllint --format --encode utf-8 -o newfile.xml 'Sample Report.xml'  

No comments:

Post a Comment