Saturday, November 14, 2009

Fixing broken sound in flash plugin in Slackware 13.0

I upgraded my laptop to Slackware 13.0. In general, hardware support has improved. All hardware was detected automatically by HAL and UDEV. That includes formerly problematic Synaptic touchpad, both monitors attached via DVI and VGA, and Logitech Quickcam. I only needed minor adjustments to get dual screen out of the mirroring mode.

One of the minor problems was that flash plugin in Mozilla wouldn't play sound. That was despite that my username being a member of the group "audio". It turned out that if you had more than one sound device, Flash would only output sound to the first configured device (alsa card #0). When I booted the laptop with webcam attached through USB, the snd-usb-audio module loaded before snd-hda-intel, resulting in the first configured audio device (webcam) not supporting any audio output.

The workaround would be to always boot with the webcam unplugged. However, a better solution is to hint the device loading system (udev) that the built-in intel sound device needs to be loaded first. Google found me a solution in a Slackware forum at Add a file in /etc/modprobe.d containing the following instruction: "options snd slots=snd-hda-intel,snd-usb-audio". You can check the mapping of sound card slots to modules using "cat /proc/asound/modules"

References: Slackware, Where Alsa looks for default sound card, Synaptics Touchpad with HAL, Dual-screen with xrandr.

Thursday, November 12, 2009

Command line email with attachments

This is a perl script which can be used as a replacement for "mail" program, but supporting email attachments.

#!/usr/bin/perl -w

#****h* common/send_files
# send_files - sends an email with multiple file attachments
# Uses sendmail to send an email with attachments. Takes message text
# from the standard input.
# --from - From email address
# --to - To email address
# --subject - Email subject
# --file - Attach a file (use multiple times to attach multiple files)
# All the unprocessed options are treated as files to be attached
# echo "Look here" | send_files --from --to \
# --subject "Files" --file /tmp/1.txt --file /tmp/2.txt
# echo "Specify files last" | send_files --from --to \
# --subject "Files" --file /tmp/*.txt
# $Header:,v 1.6 2008/04/08 20:53:13 nsushkin Exp $
use MIME::Lite;
use MIME::Types;
use Getopt::Long;

my ($opt_from, $opt_to, $opt_subject) = ("", "", "");
my @files = ();
my $VERSION = sprintf("%d.%03d", q$Revision: 1.6 $ =~ /(\d+)\.(\d+)/);

GetOptions("from=s" => \$opt_from,
"to=s" => \$opt_to,
"subject=s" => \$opt_subject,
"file=s" => \@files);

push @files, @ARGV;
$oldC = $/;
binmode STDIN; undef $/;
$/ = $oldC;

$msg = MIME::Lite->new(
From => $opt_from,
To => $opt_to,
Subject => $opt_subject,
Type => 'TEXT',
Data => $message

'X-Mailer' => " $VERSION"

for $file (@files)
die "Not readable $file: $!" unless -r $file;
chomp (my $mimeTypeS=`file -bi "$file"`);
my MIME::Type $mimeType = MIME::Types->new->type($mimeTypeS);
chomp (my $fileName=`basename "$file"`);

Type => $mimeTypeS,
Path => $file,
Filename => $fileName,
Encoding => ($mimeType->mediaType eq 'text' ? 'quoted-printable' : 'base64')