Sunday, July 20, 2008

Using KDialog to create pop-ups

Info from following URLs:
http://techbase.kde.org/Development/Tutorials/Shell_Scripting_with_KDE_Dialogs

Recently, the thought of putting a checklist for Audacity came to my mind. It is to remind the user (whether it be myself or the church PA crew who is recording the sermons) of 3 things: check the power, check the microphone volume, and save by using "Export as MP3".

I was thinking of printing a label and pasting it on the keyboard wrist rest area, but I decided not to spoil the surface, and so, the idea of pop-ups popped up :P

I used KDialog, a built-in KDE commandline application. You can either do a "man kdialog" to read the manual or go to the URL above. It's quite powerful and versatile, but I will just focus on a simple messagebox pop-up in this post.

I created a bash script which will pop up a message. When the user presses Enter or clicks OK, Audacity will be launched. So now, I have replaced the Audacity entry in my Easy Mode GUI to call this script instead of launching Audacity directly.

  1. Press Ctrl-Alt-T to open the terminal console.

  2. Type "sudo nano /usr/bin/audacity-checklist" to create the bash script.

  3. Type out the contents below.

    #!/bin/bash

    title="Audio Recording Checklist"
    msg1="1) Have you plugged in the power and SWITCHED IT ON?"
    msg2="2) Check that the microphone volume is at ONE-QUARTER of the maximum value."
    msg3="3) When saving, use 'Export as MP3', NOT 'Save Project As'."

    myMsg=$title'\n'$msg1'\n'$msg2'\n'$msg3
    nohup kdialog -msgbox "$myMsg"

    nohup audacity
    exit 0

  4. Press Ctrl-O to save and Ctrl-X to exit.

  5. Set the correct permissions to execute by typing
    "sudo chmod 755 /usr/bin/audacity-checklist"

  6. Try it out by typing "audacity-checklist". A pop-up will appear as following:

One new thing I learned while doing this script was the concatenating of strings. To combine msg1 and msg2 together and save as myMsg, type "myMsg=$msg1$msg2". There should be no spaces in between. To insert any spaces or text, insert them in single quotes. 3 examples are shown below:

msg1="a"
msg2="b"

#gives "ab"
echo $msg1$msg2

#gives "a b"
echo $msg1' '$msg2

#gives "S$a - b**"
echo 'S$'$msg1' - '$msg2'**'

(^ v ^)

No comments: