Zenity Exit / Shutdown Script for Openbox

Finally got around to doing this.

Use the zip file included at the bottom, as all the double hyphens get lost on this blog.
Also, depending on with version of zenity you have (e.g. on Debian Squeeze / #!-10), you may need to remove the  “- – no-cancel” options in the second half of the script. Enjoy 🙂

Continue reading

Recording with ALSA staring me in the face (and midi playback)

Finding the right app to record stuff is a bit of a pain on linux, and playing back midi files can be a trial also. But everything you need is right there in your alsa-utils package. Open up a terminal and let’s get going!

Recording from a microphone:

 arecord -f cd -t wav -c 2 -D plughw:1,0 foobar.wav

This will record you microphone input from your chosen soundcard (in this case card 1, device 0) at 2 channel CD quality, outputting to a wav file for you to play with later. To playback your recording:

aplay foobar.wav

For more information and options, simply type:

man aplay

OK, to play back midi files, you may need to ensure you have timidity installed. Then find a midi file (*.mid) or a kar file (*.kar) and download it. Then it is simply:

 aplaymidi -l

to find an open port, in my case 128:0, then:

 aplaymidi mymidifile.mid

If you want to get the best out of kar files, then install pykaraoke, it will play back the midi and highlight the lyrics through the song 🙂

Another Useful Copy Command

I last came up with this subject a while ago, whilst working on my own backup. Been needing something slightly different, which allows pulling out files of the same type. This one uses find rather than a straight cp function.

 find /pathtoinputdir/ -name “*.*” -type f -exec cp -urvp ‘{}’ /pathtooutputdir ;

I’ll break it down again:

 find /pathtoinputdir/ (pretty obvious, you could use just / to search your whole drive)

 -name “*.*”  (what to search for, replace *.* with anything you want to search for, but say you wanted to find all your jpg files, change it to *.jpg)

-type -f   (brings back files as opposed to directories)

-exec   (allows a function to run based upon what is found by find)

cp -urvp ‘{}’  (the copy with arguments and some magic (the brackets) which allows files and directories with spaces, newlines etc. See my other post to get descriptions of the cp arguments. You could replace cp with mv if you wanted to move and not copy)

/pathtooutputdir  (straight forward again, I create it first)

;    (more magic to go with the brackets)

Word of warning, if you have lots of files with the same name but different contents, you will overwrite the older ones with the latest one, regardless of content

Permanently Remove Files with Zenity (Thunar custom action)

 Have previously used xdialog for this, but it was time to update to zenity

zenity –question –width 640 –height 240 –title=”Permanently Remove Files” –text=”Are you sure you want to remove these files? nn %N”; if [ $? = 0 ] ; then rm -r %F ; else exit; fi

You do get a sanity check before you decide to delete, and of course, DON’T run this on /        🙂

Terminal Fight solved by Zenity (Thunar Custom Actions)

Love my thunar custom actions, and all I wanted to do was run mediainfo against a media file to see how it was made etc. Trying to do this with just xfce4-terminal was a pita. This simple line throws the info up in a zenity info dialog:

mediainfo %f | zenity –width=640 –height=480 –text-info

Unfortunately you don’t get the nice alignment you get in a terminal but hey…

Useful copy command for backing up

Don’t like backup programs, but I do like cp. I save all my work to an external HDD but I like to make a copy of this onto my server, prior to burning. As I don’t do things in sequence, I may need to make several “backups” before commiting to disk, so needed an easy way of only copying over changed or new files:

cp -urvp /pathto/externaldrive/* /pathto/backup/directory/

What does it all do?

cp         the copy command

-u         update only new or changed files with a newer date

-r          recursive to all sub directories

-v          verbose, tell me what is happening

-p          preserve file attributes

In my case, the path to the external HDD is /media/HANDY120/* – (the device is a Fujitsu HandyDrive 120GB) . Don’t forget the / and the * at the end to ensure everything on the drive is copied.

The path to the backup location can be anywhere, but you must use the same route each time