Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

View non-Mac Roman files in FileMerge Apps
FileMerge (included with the Xcode developer tools) is a great tool for comparing different versions of text files (and PDF files, as I showed in a previous hint). But it wants the files to be Mac-Roman encoded, which is strange since everything else on a Mac uses UTF-8 nowadays. Here's how to show different file encodings in FileMerge.

This bash script uses the file utility to guess the text encoding of a file. If it is ISO-8859-* or UTF-8, then the file is transformed to Mac-Roman encoding, otherwise the file is not transformed:
#!/bin/bash
charset=`file -I "$1" | sed "s/^.*charset=//"`
case $charset in
  iso-8859* | utf-8 ) 
  iconv -c -f $charset -t MacRoman "$1"
  ;;
  * )
  cat "$1"
  ;;
esac
Create a file (e.g., convert_text_to_macroman.sh) and put it somewhere (e.g., in ~/bin). Make the script executable:
$ chmod a+x ~/bin/convert_text_to_macroman.sh
Now start FileMerge and go to the Preferences. Select the Filter tab and click in an empty row to start a new filter. Type txt in the Extension column, and put the following in the Filter column:
~/bin/convert_text_to_macroman.sh $(FILE)
Now you can try to compare two files in Latin-1 or UTF-8 encoding using FileMerge. If you want to use the filter for several different extensions, I guess you have to create one row for each extension.
    •    
  • Currently 2.07 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (14 votes cast)
 
[7,158 views]  

View non-Mac Roman files in FileMerge | 9 comments | Create New Account
Click here to return to the 'View non-Mac Roman files in FileMerge' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
View non-Mac Roman files in FileMerge
Authored by: Geobunny on Dec 01, '09 08:07:51AM

Not sure I understand the need for this one. FileMerge works fine on UTF-8 files for me.



[ Reply to This | # ]
View non-Mac Roman files in FileMerge
Authored by: OverZealous on Dec 01, '09 08:27:56AM

Ditto here. I've never had a problem with UTF-8 files of a wide variety of (text-based) formats, even those created on other OSes.

Is it possible the original submitter has something else wrong with their files?



[ Reply to This | # ]
View non-Mac Roman files in FileMerge
Authored by: VxJasonxV on Dec 01, '09 09:50:23AM

I'm no longer text, I've now become...

MACRO, MAN!!!!!!

(Sorry, had to, that filename just looked different to me.)



[ Reply to This | # ]
View non-Mac Roman files in FileMerge
Authored by: unforeseen:X11 on Dec 01, '09 10:57:40AM

Hilarious! :D

---
this is not the sig you`re looking for.



[ Reply to This | # ]
View non-Mac Roman files in FileMerge
Authored by: fds on Dec 01, '09 10:51:27AM
The real hint would be is that you merely need to set the text encoding extended attribute correctly, something that Xcode and most current Mac text editors will already do on their own.

Or you can just drop into Terminal and set it yourself:
xattr -w com.apple.TextEncoding 'UTF-8;134217984' filename



[ Reply to This | # ]
View non-Mac Roman files in FileMerge
Authored by: unforeseen:X11 on Dec 01, '09 10:56:40AM

Yes, that's the real problem, files not having the right attributes. FileMerge can handle a variety of file encodings.

---
this is not the sig you`re looking for.



[ Reply to This | # ]
What about non-Mac-originated files?
Authored by: hamarkus on Dec 02, '09 06:16:28AM

I have to admit, I never had problems with file encoding and FileMerge and I definitely use a lot of file stored on non-HFS systems and edited by non-Mac computers.



[ Reply to This | # ]
View non-Mac Roman files in FileMerge
Authored by: g_mocken on Mar 28, '10 08:24:34AM

If you are using Subversion for SCM in Xcode, then all extended attributes are lost on check-in. In this case the original hint is very useful (unless someone knows a way to put HFS extended attributes into subversion properties).



[ Reply to This | # ]
View non-Mac Roman files in FileMerge
Authored by: vniks on Dec 12, '09 05:18:54PM

How to do in reverser format? Mac-Roman to UTF ?? Is there any script available?



[ Reply to This | # ]