Archive

Posts Tagged ‘encoding’

Converting Windows characters to Mac and vice versa – Filter for BBEdit

06:27 PM No comments

When working with scripts written in perl or php, the encoding of special german characters like “ü” (ue), “ö” (oe) and “ä” (ae) can’t be set correctly, since the file-encoding needs to be set to “Mac OS Roman” with “Unix Linefeeds (LF)”. So these special characters, called “Umlaute” gets mapped to untypable characters in the ASCII-table.

Due to the simple and effective integration of perl into BBEdit, there is an easy solution for this problem: A trivial perl script with some Regular Expressions, that replace all characters within a selection by the correct character.

The script for converting Windows to Mac looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
#!/usr/bin/perl -w
 
while(<>) {
	my $line = $_;
	$line =~ s/ƒ/Ä/g;
	$line =~ s/÷/Ö/g;
	$line =~ s/‹/Ü/g;
	$line =~ s/fl/ß/g;
	$line =~ s/‰/ä/g;
	$line =~ s/ˆ/ö/g;
	$line =~ s/¸/ü/g;
	print $line;
}

And verci versus: the script for Mac to Windows looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
#!/usr/bin/perl -w
 
while(<>) {
	my $line = $_;
	$line =~ s/Ä/ƒ/g;
	$line =~ s/Ö/÷/g;
	$line =~ s/Ü/‹/g;
	$line =~ s/ß/fl/g;
	$line =~ s/ä/‰/g;
	$line =~ s/ö/ˆ/g;
	$line =~ s/ü/¸/g;
	print $line;
}

You can also download the two scripts here: Download the scripts for free

Installation:

Copy the two files into your BBEdit “Application Support”-folder, located in your userfolder at:

~/Library/Application Support/BBEdit/Unix Support/Unix Filters/

Unix Filters directory after installation

Unix Filters directory after installation

So your “Unix Filters”-directory will now look something like this, as showed in the picture right standing.

If you create the scripts yourself, please keep in mind that the linefeed format of the file must be set to “Unix (LF)” for the scripts to work properly.

Here you find your new Filter

Here you find your new Filter

After you installed the script, you have to restart BBEdit. To use the filter, simply select the text you want to change. Then select the Filter you want to apply from the “#!” menu to do the conversion.

Additionally characters can be added to this example. Please keep in mind, that you may not break the Regular Expression. A good reference for Regular Expressions can be found at http://de.selfhtml.org.

This is an easy way to deal with a correct ISO-Latin 1 (ISO 8859-1) under BBEdit, using the Mac Roman encoding without having any trouble.

Example:

Here you can see an example of the result of the Filter:

A text in Mac-Roman, selected for conversion

A text in Mac-Roman, selected for conversion

After selecting “Konv Mac>Win.pl”:

The characters within the selection got converted

The characters within the selection got converted

Post to Twitter Tweet This Post