2008-12-05

Howto make the Play/Pause key work for Amarok in Kubuntu 8.10

After installing Kubuntu 8.10 i could no longer press the "Play/Pause" key on my multimedia keyboard to pause a playing track in Amarok, instead it would restart the track.

It turned out that Kubuntu do set there own global shortcuts (Play in Amarok is assigned to the XF86AudioPlay key) for Amarok so you need to change them.

  1. In Amarok go to Settings -> Configure Global Shortcuts
  2. Press Defaults to reset all shortcuts
  3. Highlight the Amarok Action "Play/Pause" and select Custom Action and configure the Alternate shortcut to use XF86AudioPlay (Select the alternate radio button and click the box then press your "Play/Pause" key on your keyboard)
  4. Make sure the Amarok Action "Play" don't use the XF86AudioPlay shortcut and that the Amarok Action "Pause" is emty
  5. Assign your other multimedia keys like Stop, Next Track and Previous Track to there alternate shortcuts in Amarok

Now you should be able to use your multimedia keys on your keyboard like they used to. At least it worked for me.

2008-09-28

Linux/Unix Tips & Tricks: The sed command

Sed (Stream EDitor) is a UNIX command that reads input, line by line from a text file or stdin (standard input) and applying the user specified operation and outputs the result to stdout (standard output). It's very good for searching for specific text patterns using regular expression and then perform some manipulation on it. A typical sed usage looks like this "sed -e 's/searchForOldStuff/replaceWithNewStuff/g' inputFileName > outputFileName". Where s stands for substitute, g for global, meaning replace all matching occurrences in a line, searchForOldStuff is the regular expression to search for and replaceWithNewStuff is what to replace it with.

Here are some handy tricks with sed.


Replace first occurrence of cat in every line with dog:
sed -e 's/cat/dog/'

Replace ALL occurrence of cat with dog:
sed -e 's/cat/dog/g'

Replace ALL occurrence of cat with dog ignoring case:
sed -e 's/cat/dog/gi'

Delete all empty (with only a carriage return) lines:
sed -e '/^$/d' or sed -e 's/^$//'

Delete all lines with only white spaces (spaces and tabs):
sed -e '/^[ \t]*$/d' or sed -e 's/^[ \t]*$//'

Delete all empty lines or lines with only whit spaces:
sed -e '/^$/d' -e '/^[ \t]*$/d'

Delete leading white space from all lines:
sed -e '/^$/d' -e 's/^[ \t]*//'

Delete trailing white spaces from all lines:
sed -e 's/[ \t]*$//'

Delete leading and trailing white spaces from all lines:
sed -e 's/^[ \t]*//' -e 's/[ \t]*$//' or sed -e 's/^[ \t]*;[ \t]*$//'

Delete lines from the first to and including the first not blank line:
sed '1,/^$/d'

Insert something at the beginning of each line:
sed -e 's/^/thiswillbeinserted/'

Insert something at the end of each line:
sed -e 's/$/thiswillbeinserted/'

Number each line of a file:
sed = yourfile.txt | sed -e 'N;s/n//'

Number each line of a file (row number and a tab):
sed = yourfile.txt | sed -e 'N;s/n/t/'

Number each line of a file (row number and a space):
sed = yourfile.txt | sed -e 'N;s/n/ /'

Reverse order of the lines:
sed -e '1!G;h;$!d' or sed -n '1!G;h;$p'

Reverse each character on the line:
sed -e '/n/!G;s/(.)(.*n)/&21/;//D;s/.//'

Convert a file with Unix newlines (CR) to DOS/Windows newlines (CRLF):
sed 's/$/r/' or sed 's/$'"/`echo \r`/"

Convert a file with DOS newlines to Unix (to make the special character '^M' press Ctrl+v and Ctrl+m):
sed 's/^M$//'

Insert a empty line after every line:
sed -e G

Insert only a empty line where not already a empty line:
sed -e '/^$/d;G'

Count number of lines:
sed -n '$='

Align all text to the right at column 79:
sed -e :a -e 's/^.{1,78}$/ &/;ta'

Center all text in the middle of 79-column width. Leading and trailing spaces are discarding.
sed -e :a -e 's/^.{1,77}$/ &/;ta' -e 's/( *)1/1/'

Print the first line:
sed q

Print the first 10 lines:
sed 10q

Print the last line:
sed '$!d'

Print the last 10 lines:
sed -e :a -e '$q;N;11,$D;ba'

Print the paragraph if it contains MYREGEX (blank lines separate paragraphs):
sed -e '/./{H;$!d;}' -e 'x;/MYREGEX/!d;'

Join pairs of lines (side-by-side) from two files:
sed '$!N;s/n/ /'

Remove html tags from a file:
sed -n '/^$/!{s/<[^>]*>//g;p;}'

Make a backup of the file using specified extension (.bak):
sed -i.bak 's/something/example/'

If you know some other handy sed scripts please post them here.

2008-09-25

Howto kill a process in linux

If you have a program that using a lot of your computers resources or not responding it can be necessary to kill it the hard way, here are some ways to do that.

  • With the kill command.
    If you know the PID (every process in your system has a uniq number, that's the PID, shortcut for Process IDentifier ) of the process, you can send it a signal with the kill command. There are several signals you can send and depending on the process it will be terminated. Some of the most common signals to end a process are SIGHUP, SIGINT, SIGTERM and SIGKILL. SIGTERM is the signal you should try first and if that don't work use SIGKILL. To send a signal to the process with the kill command type this in a console: "kill -SIGNAL PID" where you replacing SIGNAL with a signal and PID with the processes process identifier number. To find out the PID of a process you can use one of the "pidof", "pgrep", "top", or "ps" command in a console.

  • With the pkill command.
    pkill is a command similar to kill in that it will send signals to a process to terminate it, the difference to kill is that you don't need know it's PID, instead you terminate a process based on its name. If you type "pkill firefox" in a console pkill will terminate all processes with firefox in it's name. pkill will by default send a SIGTERM signal but that can be changed. WARNING! be careful as pkill will terminate ALL your processes that have what you specified in its name.

  • With the xkill command.
    In X-Windows you can kill processes that have a window with the xkill command. Running xkill will get you a mouse cursor of a death skull and if you click with it on a window it will be terminated. In KDE pressing the Ctrl+Alt+Esc keyboard shortcut will run the xkill command.

  • With KDE.
    In a default KDE setup you can press Ctrl+Esc keyboard shortcut to open a window with all processes listed and from where you can right click on one and choose a signal to send to it.
  • With SysRq.
    With the SysRq keyboard key you can make the kernel do some really powerful stuff with you system. Type "cat /proc/sys/kernel/sysrq" in a console to see if SysRq it is enabled, if the result is "1" it's enabled or else you can activate it by running one of this command as root "echo 1 > /proc/sys/kernel/sysrq" or with the sysctl command like this "sysctl -w kernel.sysrq=1". By pressing any of the keyboard shortcuts below you will tell the kernel to do what's described in the parentheses.

    Alt+SysRq+r (The r stands for put keyboard in raw mode)
    Alt+SysRq+s (The s for sync the disk)
    Alt+SysRq+e (The e for terminate all processes)
    Alt+SysRq+i (The i for kill all processes)
    Alt+SysRq+u (The u for remount all file systems read only)
    Alt+SysRq+b (The b for reboot the system)
Beware that using some of these SysRq commands it is very dangerous as it will kill all processes in your system and you will loose all data that are not saved. Use it at your own risk and only as a last option.

Good luck killing your system.

2008-04-17

Things that sucks in Kubuntu 7.10 AMD64

There are several things in Kubuntu 7.10 that I don't like and it feels like it's not mature enough to be released at all. I wounder what they were thinking when they made some of the choices.

  1. Bootsplash
    The Bootsplash screen don't work on AMD64. The screen stays black until you are presented with the login dialog. As far as I understand it, Kubunt uses VESA for displaying the bootscreen and the VESA driver in the kernel dont support AMD64. It should be mentioned somewhere in the installation or in the documentation.
  2. Firefox
    Several plugins for Firefox like Flash and Java don't work with Firefox 64-bit that is installed. Well, it's not Kubuntu developers fault, but I think there should be an option to install Firefox 32-bit because everything then would work. There are unsupported ways like nswrapperplugin and Firefox32.
  3. KMilo
    KMilo is a KDE Service that would make your keyboard multimedia keys work. Kubuntu uses KDE 3.5.8 and KMilo in that version has bugs that, for instance, won´t let you change the volyme more than between 0% - 11%.
  4. Dolphin
    Dolphin is the default file manager in Kubuntu 7.10. The version in Kubuntu is unmature, buggy, unsupported and lacks functions that all file manager should have. If you want a real file manager look at Krusader.
  5. Strigi
    Strigi is a desktop search program which will scan and index files in your home folder so that you later can search for file names or/and contents. Strigi is installed by default and would be OK if only it worked. Strigi wasn't able to finish indexing the files and I couldn't search for any information, because it just kept crashing.
  6. Amarok and Kid3
    Amarok is a music organiser and player. Kid3 is a program to add and edit the metadata in music files. Neither of the programs can show coverart that are embedded in the ID3 tag of MP3 files. The images will be displayed distordered while Easytag display them just fine. This could be a bug in Taglib or some other library used by KDE and Amarok.
  7. DLink DWL-G122 Wireless network card
    DWL-G122 is a wireless USB network card. Despite claims on the forum that it would work in Kubuntu 7.10 with default drivers, it dosen't work for me. When I insert DWL-G122, Kubuntu will load the drivers and it seems OK but I can not connect to my router. The solution for me was to download and compile the driver from serialmonkey.com. Because that worked, Kubuntu should use that driver instead.
That's just some of the bugs and annoying things i found in Kubuntu 7.10 and I'm sure i can find plenty of more. Kubuntu 8.10 Hardy will be out soon and i hope it will fix some of the things or else i think i will search for another Linux distribution.

2008-04-16

Howto make firefox work in Ubuntu AMD64 with flash and java

One of the biggest problem i had when i first installed Kubuntu 7.10 64-bit is that i couldn't run firefox with the java and flash plugins. The problem is that Adobe has no 64-bit version of flash and Sun java plugins dont work ether. There is a solution and it is to install a 32-bit firefox and the 32-bit plugins will work. So how do you do that you may ask. There is a thread on the ubuntu forum with a script that can download firefox, flash, java, install them and configure them and you don't even have to uninstall your 64-bit firefox. Go to the thread on ubuntuforums.org and click on the link "The new script will work on Dapper, Edgy, Feisty, and Gutsy" to download the script file.

If you want to know more about what the script do read through "Manual howto" section. To install Firefox and the plugins open a terminal and go to the catalog where you saved the downloaded file, unpack it and run it with the command:

tar -xvf ff32-3in1-*.tar.gz && cd ff32-3in1 && sudo ./3in1

It will ask you some question, enter you choices and when it has finished you should now have a firefox32 menu entry. Start firefox32 from the start menu and write about:plugins in the adressfield and you will be presented with a side over all plugins Firefox can use. Try to watch some videos from youtube to test that flash is working. Go to javatester.org to test that java is working.

Happy surfing

Update:
As of Kubuntu Hardy firefox and flash work "out of the box" for me after installing flashplugin-nonfree.

2008-04-07

Google Kalender med svenska helgdagar

Under det senaste året har jag använt Google Kalender som min primära almanacka.

Det som är så bra med Google Kalender är att den alltid finns tillgänglig online på nätet och att jag kan komma åt den från vilken dator som helst som har internet.

När jag registrerar en händelse i Google kalendern så kan jag ange när och hur ofta jag vill bli påmind om den händelsen. Google Kalender skickar då ut ett mail till min GMail-adress eller som en popup om man anväder GTalk. Detta passar mig perfekt eftersom jag normalt alltid glömmer att skriva upp, för mig viktiga händelser, i en vanlig fickkalender och skulle jag någon gång komma ihåg att göra det så skulle det kvitta, för jag skulle ändå inte komma ihåg att ta med mig kalendern.

Jag har lagt upp det så att jag har en separat kalender över helgdagar och andra särskilda dagar, en med födelsedagar, en för privata händelser, en för namnsdagar och slutligen en för sånt som rör min dotter.

Nackdelen med de flesta kalenderprogram är att de saknar de svenska helgdagarna. För år 2007 satt jag och skrev in alla helgdagarna själv eftersom jag inte hittade någon kalender online med helgdagar som gick att importera i Google Kalender. Jag sökte på nätet efter en fullständig kalender för 2008 och helst i iCalendar format så att jag lätt kunde importera den. Jag hittade två länkar till personer som har satt ihop diverse kalendrar över svenska helgdagar, flaggdagar och andra speciella dagar och lagt upp dem så man kan ladda ner och använda gratis.

Så hur gör man då för att få en kalender med svenska helgdagar i Google Kalender? Börja med att surfa till en av sidorna (se länkar nedan) och ladda ner den kalender du vill ha! På Camoflage.org så laddar du ner kalendern "Svenska helgdagar 2008 - för Macanvändare och iCal", packar upp filen och loggar in på din Google Kalender. På vänstra sidan klickar du på "Hantera kalendrar", sedan "Skapa ny kalender", väljer ett kalendernamn t. ex. "Helgdagar 2008" och klickar på "Skapa Kalender"-knappen.

Därefter klickar du på "Lägg till" till vänster och välj "Importera kalender". I steg 1 klickar du på "Bläddra..." och bläddrar fram till filen "helg_2008.ics" från zip-filen du packade upp. I steg 2 väljer du kalendern "Helgdagar 2008" du skapade . I steg 3 klickar du på "Importera". Om allt gick bra ska du nu ha en ny kalender med de importerade helgdagarna.

CS Pro finns det flera olika kalendrar, ladda ner de du vill ha och följ samma procedur som ovan för att importera dem.

Stötta gärna de som gjort kalendrarna genom att skänka en slant. Instruktioner finns på deras respektive sidor.

http://www.camouflage.org/helg2008/

http://www.cs.se/how/calendar/