lunes, 15 de marzo de 2010

Bash Script for Muting front Speaker

The following script will evaluate your "Speaker" audio output and change it to 0% or 100%, without modifying any other output.
This can be used to play audio from your speakers and your headphone output at the same time, or to roughly work-around the issue affecting some laptops where the speaker doesnt mute when a headphone is plugged (AKA jacksens not working)
It requires Alsamixer

export i=`amixer sget Speaker | grep 'Front Left:' | cut -d'%' -f1 | rev | cut -d'[' -f1`
if [ $i -eq 0 ]
then
amixer sset Speaker 100
else
amixer sset Speaker 0
fi

The script works by getting the amixer output for "Speaker" (you might need to change that); chopping it untill only a value is remaining (hence the cut | rev | cut); evaluating the output and then setting the volume to 100% or 0%

If this does not work you might need to change the Speaker output for some other, you can find your output's names by entering
amixer

in the terminal, and then changing any occurence of Speaker for your desired output's name.

miércoles, 10 de marzo de 2010

Switch between window managers

The following script will allow you to switch between Compiz and xfwm4 (xfce window manager):

#!/bin/sh
SERVICE='compiz'

if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
xfwm4 --replace
else
compiz --replace
fi


If you want to adapt this script to suit your needs, SERVICE= is the name of the process that will be tested if its running.
'then' is the action that will be done if the process is runing (in this case, launch xfwm4 with --replace argument for taking over compiz)
'else' is the action that will be done if the process is NOT running (in this case, launch compiz with --replace argument for taking over wfmw4

Load an entire webcomic (or part of it) at once

This will require Firefox and FlashGot.

Certain webcomics like www.sinfest.net store their images in a restricted folder, therefore we cant access them directly.
However, I noticed the images follow a naming pattern, which means a Regular Expresion should be able to find all the possible matches.
This is what i did:
1) Navigate to your webcomic, right click the strip, and click on "View image", take note on the files name and path (in this case, http://www.sinfest.net/comikaze/comics/2010-03-10.gif)
2) Navigate to the previous strip, and click on "View image" once more, take note on the name
(in this case, 2010-03-09.gif)
3) Now we need to identify a pattern, in this case, we can note the images are named [year]-[month]-[day].gif
4) Navigate to the first strip of the webcomic, so we can know from where to start.
5) Click on Tools, FlashGot, Build Gallery
6) Fill in the following:
In the first line, puth the entire path to an image, then change the year to [YearOfFirstStrip-YearOfLastStrip] (in this case: [2000-2010]). Do the same for month and days, in the end it should look like this: http://www.sinfest.net/comikaze/comics/[2000-2010]-[01-12]-[01-31].gif
7) Click on the arrow pointing downards, and change the file extension to .gif again
8) Wait for it to load and enjoy

-It is advised to load a few or one year at a time.
-Some images will never load because they simply don't exist, for example 2004-02-31.gif will never load because February will never have a 31th day.
-If you want to store the images into your hard drive, save the page as Web Page (Complete).

Automatically store music loaded into cache

The following script will allow you to automatically move music files from the firefox cache to any directory.
This should be in a single line, and you must edit both the [random folder name] and desired path/to/target to fit your needs:
file --mime-type home/[your username]/.mozilla/firefoz/[random folder name]/Cache/* | grep -i audio | cut -d':' -f1 | xargs -I{} mv {} /path/to/target/


It will identify Audio files regardless their extension (if present) and move them to the directory you specify in the end.

Depending on the page you are using, your cache may or may not be automatically deleted when the audio file is no longer needed. You can avoid that by using Proxomitron, which runs perfectly under Wine. Just install it, load it, and point your firefox to use proxy localhost, port 8080.

One last thing you might want is to point your preferred audio player to automatically scan your target directory, since the files wont have a descriptive name.