KDE Shutdown, Logout, Restart

Posted On May 16, 2008

Filed under Shell
Tags: , , , , , ,

Comments Dropped 2 responses

Inspired by this post.

It is interesting how simple specialised devices cope with their functions much better than a all-in-one PC. Sometimes, I wish to fall asleep with some music on. But how annoying it becomes, when you have to get up in the middle of the night to turn off your PC, which has been playing something all this time. Digital radios have mastered the trick decades ago. Of course there is a way to make a PC do it.

Running linux, I thought that it should be fairly straightforward to shut it down after say half an hour automatically.

Something like shutdown (below) will kill the X. The KDE then will just exit without saving the session. Next time you log on, you will see some session from a distant past. If you do this often, it gets really annoying. Also this requires superuser privileges on some distributions.

/sbin/shutdown -h now "Power button pressed"
# or
halt

Then how to make KDE quit without calling any dialogs (I am sound asleep by this time and I can’t afford to wake up and press ‘OK’)? There is a way.

dcop ksmserver ksmserver logout 0 2 2

The three numbers are explained below (see source):

First parameter: confirm
Obey the user’s confirmation setting: -1
Don’t confirm, shutdown without asking: 0
Always confirm, ask even if the user turned it off: 1
Second parameter: type
Select previous action or the default if it’s the first time: -1
Only log out: 0
Log out and reboot the machine: 1
Log out and halt the machine: 2
Third parameter: mode
Select previous mode or the default if it’s the first time: -1
Schedule a shutdown (halt or reboot) for the time all active sessions have
exited: 0
Shut down, if no sessions are active. Otherwise do nothing: 1
Force shutdown. Kill any possibly active sessions: 2
Pop up a dialog asking the user what to do if sessions are still active: 3

MP3 Tags to Unicode

If you have some old mp3 files, where the tag information is not in english and years ago you have used an encoding your current music player does not understand? The answer is easy – covert to Unicode. First I tried doing it manually, and it works if you have less than 10 tracks. Let’s just say I had more…

I have tried several approaches (all on linux): id3iconv-0.2.1, EasyTag, etc.

It is possible I was missing something, but I could accomplish my task and change the encoding. id3iconv-0.2.1 just removed foreign characters, so that no recovery would have helped (good I had a backup).

And then I found a set of python tools: python-mutagen-1.11.

It was enough to one script (below) and all my tracks had Unicode tags:


mid3iconv -e CP1251 *.mp3

You have to specify the incoming encoding, mine was CP1251 (Windows – Cyrillic).

After trying lots of these tools, I was kind of skeptic about this one as well. If you run it in verbose dry run mode, it will say what it would normally just do. This way you can get full confidence that you specified the initial encoding correctly and that the tool will work at all without changing anything.


mid3iconv -e CP1251 -p -d *.mp3