Thursday, June 18, 2009

MacOS X: Changing Keyboard Layout Permanently

I am Thai, live in Germany, got a German-keyboard MacBook Pro, and always *have to* write stuff in English.
I always need at least two keyboard layouts, one for English and one for Thai.
(I could have used German layout for both English and German languages but LaTeX syntax is not German-friendly.)

Anyway, in the end, I got German keyboard and use English and Thai layouts.
To get two layouts of my choice, I could just set it through International setting in System Preferences like it is shown here.
....Except that it is not.

Sometimes and sometimes only, after I turn off the machine and turn it on again, the layouts mysteriously change back to German (which was my default one).
I was wondering for a long time why the layout does not stick.

Now, I know why.
Non-root users have no rights to change some preferences.
That's why when I change the layout, it switches back to the default one which was set by root when I installed the OS (which, unlike Windows, was eons ago).
To permanently change the layout, you have to access System Preferences as root.

To do so, type t
he following command in the Terminal (if you don't know what root or Terminal is, I guess it is better to ask someone who knows to do it for you. It is pretty safe to follow the next step, but just in case.):
sudo /System/Library/CoreServices/Setup Assistant.app\ /Contents/MacOS/Setup Assistant
Now, you can change your layouts as you like and it will stick.

Please note that using sudo and do stuff as root is highly not recommended.
This is because you could potentially harm your system by doing things which you normally are not allowed to do.
However, if you just quickly set the layout and quit the Sys Pref, I think you are pretty safe.

This solution is originally posted here.

Friday, June 12, 2009

Searching Text in Files (Unix/Linux)

I was looking for a way to find files in a directory which contain specific text.
The results should be only the name of the files, not the lines in the files that contain the text.
(That is the way grep normally do.)

The solution is very simple:

grep -i -r -l "text"

where
-i = ignore case (up to you though),
-r = search recursively through sub-directories,
-l = returns only the file names, not the line contents.
and indeed, text has to be replaced with your text but the quotation marks have to be intact.