David's Tips and Tricks

Convert A4 Size PostScript to PDF using GhostScript

          psFile=<PostScript-File>;                            \
              cat $psFile |                                    \
              gs -q -dNOPAUSE -sDEVICE=pdfwrite -sPAPERSIZE=a4 \
                 -sOutputFile=$(dirname $psFile)/$(basename $psFile .ps).pdf -

YouTube Download

          youtube-dl "URL-of-Video-to-Download"
          youtube-dl "http://www.youtube.com/watch?v=Zcxh_XpuNS0"

      1)  Use synoptic package manager to install "youtube-dl"
      2)  Update the installed version of youtube-dl:
             sudo youtube-dl -U
      3)  Update the installed version of youtube-dl a second time:
             sudo youtube-dl -U

Convert YouTube Downloaded .flv File to mp3

          ffmpeg -i xxxx.flv -acodec libmp3lame xxxx.mp3

      1)  Use synoptic package manager to install "ffmpeg"
      2)  Use synoptic package manager to install "libavutil-extra-50"

Convert ogg file to mp3

          for i in *.ogg; do
            soundconverter -b -m audio/mpeg -s .mp3 $i

Displaying and Modifying Tags in flac Files

      flac Tags can be displayed via the command:

          metaflac --list <flac-file> | grep comment

      Tags can be replaced thus:

          metaflac --remove-tag=$tag "--set-tag=$tag=<new-tag-value>" <flac-file>
          <tag-name> is one of ALBUM

       To make cutting and pasting the examples easier:

          tag=ALBUM;       metaflac --remove-tag=$tag "--set-tag=$tag=XXX" <flac-file>
          tag=ARTIST;      metaflac --remove-tag=$tag "--set-tag=$tag=XXX" <flac-file>
          tag=TITLE;       metaflac --remove-tag=$tag "--set-tag=$tag=XXX" <flac-file>
          tag=TRACKNUMBER; metaflac --remove-tag=$tag "--set-tag=$tag=XXX" <flac-file>
          tag=DATE;        metaflac --remove-tag=$tag "--set-tag=$tag=XXX" <flac-file>
          tag=GENRE;       metaflac --remove-tag=$tag "--set-tag=$tag=XXX" <flac-file>
          tag=COMMENTS;    metaflac --remove-tag=$tag "--set-tag=$tag=XXX" <flac-file>

       For a GUI, one can use:

          easytag &

Convert flac file to mp3 file

          for i in *.flac; do
               title="$(metaflac --export-tags-to=- $i | grep TITLE       | cut -d= -f2)"
              artist="$(metaflac --export-tags-to=- $i | grep ARTIST      | cut -d= -f2)"
               album="$(metaflac --export-tags-to=- $i | grep ALBUM       | cut -d= -f2)"
                year="$(metaflac --export-tags-to=- $i | grep DATE        | cut -d= -f2)"
               track="$(metaflac --export-tags-to=- $i | grep TRACKNUMBER | cut -d= -f2)"
             comment="$(metaflac --export-tags-to=- $i | grep COMMENTS    | cut -d= -f2)"
            flac -dc $i | \
            lame -b 128 -m s   \
                 --tt "$title" \
                 --ta "$artist" \
                 --tl "$album" \
                 --ty "$year" \
                 --tn "$track" \
                 --tc "$comment" \
                 - $(basename $i .flac).mp3

Convert mp3 file to flac file

          for i in *.mp3; do
            ffmpeg -i $i $(basename $i .mp3).flac

Concatenate flac files

          shntool join -o flac <flac-file> <flac-file> ...

   The output file is called joined.flac.
   Afterwards, remember to set tags in the output file.

Displaying and Modifying Tags in mp3 Files

      mp3 Tags can be displayed via the command:

          mp3info <mp3-file>

      They can be modified thus:

          mp3info -t "new-title"        <mp3-file>
          mp3info -a "new-artist"       <mp3-file>
          mp3info -l "new-album"        <mp3-file>
          mp3info -y "new-year"         <mp3-file>
          mp3info -g "new-genre"        <mp3-file>
          mp3info -c "comment"          <mp3-file>
          mp3info -n "new-track-number" <mp3-file>

       For a GUI, one can use:

          easytag &

Creating an m3u Playlist

    Assume that <m3path> is set to the name of a directory containing several
    mp3 files. The following bash commands will create an m3u playlist
    of the files. The rather tedious use or quotation marks is intended to cope with
    spaces in file and direcory names:
          if [ -d "$m3path" ]; then
            m3uName="$(basename "$m3path").m3u8"
            echo "#EXTM3U" >| "/tmp/$m3uName"
            for f in "$m3path"/*.mp3; do
              echo ========================= "$f"
              info="$(mp3info -p "#EXTINF: %S,%a - %t" "$f")"
              echo "$info" >> "/tmp/$m3uName"
              echo $(basename "$f") >> "/tmp/$m3uName"
            mv "/tmp/$m3uName" "$m3path"
            echo -e \"$m3path\" is not a directory!

Optical Character Recognition, OCR

      To perform Spanish and German OCR on a jpg file:

          jpgFile="P1000038.JPG"                    # for example
          baseName=$(echo $jpgFile | cut -d. -f1)   # Handle both ".jpg" and ".JPG" names
          jpegtopnm $jpgFile > $baseName.pnm
          tesseract -l spa+deu $baseName.pnm $baseName

      The result will be in $baseName.txt.

Turn Off the ubuntu Logout Prompt

      To turn Off the ubuntu Logout Prompt:

       gsettings set com.canonical.indicator.session \
          suppress-logout-restart-shutdown true

Lumix DMC-FS35 Digital Camera

The Panasonic Digital Camera Model DMC-FS35 is rather weak in its built-in folder manipulation capabilities. In particular, there is no way to get it to reset its photo number counter. The following link describes a way that one can do this:


Giving an Image a Transparent Background with gimp

      a) Open the image in gimp.

      b) Add an alpha-channel via Layer > Transparency > Add Alpha channel.

      c) Use a select tool, e.g. Fuzzy Select, to select the background area to be made transparent.

      d) Hit the Del key.

      e) Export the image as type png or gif.

Rotating a Movie by 90 degrees on Playback

     90 degrees clockwise:
            mplayer -vf rotate=1 <video-file>

     90 degrees counter-clockwise:
            mplayer -vf rotate=2 <video-file>

Rotating a Movie File by 90 degrees

     90 degrees clockwise:
       mencoder <input-movie> -o <output-movie> -vf rotate=1 \
         -oac pcm -ovc lavc

     90 degrees counter-clockwise:
       mencoder <input-movie> -o <output-movie> -vf rotate=2 \
         -oac pcm -ovc lavc

Rotating a Movie by 90 degrees

Note: the following does not handle the sound track of the movie. Doing that is a future project!

      1) Extract all the frames of the movie into png files:

            mplayer <inputfile> -vo png:z=8 -ao null

      2) Convert the png files to jpg files:

            for i in *.png; do
              pngtopnm $i | \
              pnmtojpeg --quality=90 >| $(basename $i .png).jpg
              echo $i

      3) Rotate all the jpg files:

            for i in *jpg; do
              jpegtran -rotate 90 $i > /tmp/$i
              mv /tmp/$i .
              echo $i

      4) Merge the jpg files back into a movie:

            mencoder "mf://*.jpg" -mf fps=30 -o <outfile>.avi \
                     -ovc lavc -lavcopts vcodec=mpeg4
            avconv -f image2 -i %08d.jpg -r 30 <outfile>.avi

Scan MultiPages using Document Feeder

    Load the pages to copy into the feeder.

    To scan in 15 pages, execute, for example:

        x=1; while [ $x -le $nPages ]; do
          echo $x
          scanimage -x 200 -y 290 \
                    --mode=Gray \
                    --resolution=300 >| img-$(printf %02d $x).pnm

    To rotate the scanned files:

        x=1; while [ $x -le $nPages ]; do
          echo $x
          pnmrotate 90 \
            img-$(printf %02d $x).pnm >| rimg-$(printf %02d $x).pnm

    To convert the rotated files to PDF:

        for i in *; do
          echo $i
          convert $i $(basename $i .pnm).pdf

Setting up a WAP-4033 Wireless Access Point from Planet

Follow this link.

Connecting an Android Device via its USB Cable

An Android USB device needs to be recognised by a ubuntu system when it is plugged in. It needs a configuration file in:


For example, an ARCHOS tablet requires a file such as /etc/udev/rules.d/51-archos.rules:

      > sudo cat /etc/udev/rules.d/51-archos.rules
      SUBSYSTEM=="usb", ATTR{idVendor}=="0e79", MODE="0666", GROUP="plugdev"

It is necessary to find the Vendor-ID of the device being connected. This link contains a list of more Vendor-IDs.

How to Install and Set Up dbWeave

      1) Use synaptic to install wine.

      2) Download the dbweave_setup.exe file from:


      3) Install dbWeave as root:

                 sudo mkdir /opt/dbWeave
                 sudo cp .../Downloads/dbweave_setup.exe /opt/dbWeave/
                 su -
                 # wine /opt/dbWeave/dbweave_setup.exe

          and specify:


          as the installation directory.

      4) dbWeave can then be started via:

                 wine /opt/dbWeave/dbw.exe

      5) Set up a ubuntu desktop file, maybe so:

              > cat /usr/share/applications/xfig.desktop
              [Desktop Entry]
              Exec=/opt/dbWeave/dbw.exe %f
              Comment=Weaving Setup Application


How to Clone an Android Project under eclipse

Using eclipse to develop apps for android, I have not found any simple way of duplicating a project to my satisfaction. The following seems to work. I'd appreciate suggestions on how to simplify it.

Suppose that one has an eclipse project called old_proj, and one wants to duplicate it, calling the new project new_proj:

      a) Ensure that all packages/projects in the Package Explorer view of eclipse
         are collapsed. My version of eclipse has a button that does that in a single click.

      b) Select project old_proj in the Package Explorer view, and copy it
         via Edit --> Copy.

      c) Paste the copied project via Edit --> Paste. When prompted for a new name, specify
         a provisianal name, e.g. xxxx.

      d) Click on the new project, xxxx, in the Package Explorer view, and select
         Refractor --> Rename... Specify the desired new name, e.g. new_proj, ensure that
         Update references is checked, and click OK.

      e) Continue in a terminal window:

       i)    > op=old_proj
             > np=new_proj

       ii) Set the current working directory to the base of the new project, e.g.:

             > cd ~/android/workspace/$np/

       iii) Delete the bin and gen directory trees:

             > rm -Rf bin gen

            and, if the old project was checked into CVS, remove all CVS directories:

             > for i in $(find . -name CVS); do rm -Rf $i; done

       iv) Find all directories having the old project name, and rename them to
           the new project name, e.g.:

             > for i in $(find . -type d -name $op); do
                 mv $i $(dirname $i)/$np;

       v) Find all files containing references to the old project name, e.g.:

             > find . -type f -exec grep -l $op {} \;

          These should all be ASCII files, which can be edited using sed. Check
          that this is the case before continuing to Step v).

       vi) Replace all references to the old project name with references to the
           new project name, thus:

             > for i in $(find . -type f -exec grep -l $op {} \;); do
                 sed -e s/$op/$np/g $i >| /tmp/xxxx;
                 mv /tmp/xxxx $i;

      f) Return to eclipse, select the new project in the Package Explorer window and then
         File --> Refresh. There will probably be a message about the package definition
         having changed in the Manifest, with a question about updating the Launch
         Configuration. This can be answered with Yes.

      g) Finally select Project --> Clean.... Ensure that the new project is checked, and click OK

Assuming that the old project was OK, the new one should now also be OK and have no references to the old project.