Linux Blog

Remotely Changing Windows Volume

Filed under: Shell Script Sundays — TheLinuxBlog.com at 2:41 pm on Sunday, October 18, 2009

This is not really “shell scripting” but the end result is some more bash scripts in my bin directory so what the hell? It’s going in the shell script section because its Sunday. So what?

I like to listen to music on my Windows box while I work on my Linux box. Online radio and other sounds, just get in the way too much. One of the things I wanted to do for a while was remotely control my volume so I didn’t have to use my KVM to switch over to change the volume when ever anyone came in my office.

Its actually pretty easy to control your windows volume from Linux.

At first I thought, I’d create a dummy audio device, and some how map it over. Then I figured that was overkill and I’d try something a bit easier. I have SSH via Cygwin, so all I needed was a way to control the volume locally, and I could execute the command with SSH. Having no volume utilities jump at me when I looked through the Cygwin repositories I went to look for something else.

NirCmd is an awesome utility, giving me and other Windows users the ability to do things that Linux users may take for granted, you can read about it here: http://www.nirsoft.net/utils/nircmd.html after installing it, and making sure that my corporate AV didn’t throw a hissy, it was just a matter of dumping some scripts in my bin directory and chmodding them so they would run.

Here is what they look like:

Volume Down Script: ssh windowsbox -l owen -C “nir changesysvolume -2000″

Volume Up Script: ssh windowsbox -l owen -C “nir changesysvolume 2000″

Mute: ssh windowsbox -l owen -C “nir mutesysvolume 1″

Unmute: ssh windowsbox -l owen -c “nir mutesysvolume 0″

Real simple, and the mute/unmute really comes in handy for when some one walks into my office.

Facts About Selenium

Filed under: General Linux,Linux Software — TheLinuxBlog.com at 9:22 pm on Friday, March 28, 2008

Selenium is a chemical element. What you may not know is that Selenium is also a powerful testing tool for web applications. Selenium runs its tests directly in a browser, just like real users do. It is cross platform and the developers plan to have it for the iPhone but thats another story. Selenium can run in one of two modes Core and Remote Control (RC). The RC method has a way of using distributed computing much like the way Samba allows cross compiling over multiple cpu’s. There is an IDE for Selenium that can be used to easily learn Selenium.

Enough Facts About Selenium already!

What exactly can you do with Selenium?

Well, the answer is simple. Pretty much anything that you can do with a browser Selenium can do. Its primary purpose is for developers to use as a quality assurance tool. For QA purposes you can create a test cases, run them and verify that the end result is what you expected. You can create test cases in Java, Ruby, Python, Perl, PHP or .NET.

I had a little trouble getting the Selenium driver for PHP installed so here is the how to:

sudo su
pear channel-update pear.php.net
pear install Testing_Selenium-beta
pear install PHPUnit
exit

The above allowed me to communicate with the Selenium Remote Control that I downloaded with PHP. Here is an example from their website that I have modified so that it works:

  <?php
 
set_include_path(get_include_path() . PATH_SEPARATOR . './PEAR/');
require_once 'Testing/Selenium.php';
require_once 'PHPUnit/TestCase.php';
 
class GoogleTest
{
private $selenium;
 
public function setUp()
{
$this->selenium = new Testing_Selenium("*firefox", "http://www.google.com");
$this->selenium->start();
}
 
public function tearDown()
{
$this->selenium->stop();
}
 
public function testGoogle()
{
$this->selenium->open("/");
$this->selenium->type("q", "hello world");
$this->selenium->click("btnG");
$this->selenium->waitForPageToLoad(10000);
$this->testCase("/Google Search/", $this->selenium->getTitle());
echo "<hr>";
$this->testCase("/Yeahh Search/", $this->selenium->getTitle());
 
}
 
public function testCase($regEx, $string) {
 
preg_match($regEx, $string, $matches);
 
print_r($matches);
 
}
 
}
 
$google = new GoogleTest();
 
$google->setUp();
$google->testGoogle();
$google->tearDown();
?>

Before attempting to run this you must make sure that you downloaded Selenium RC and that it is running. Selenium runs on Java so make sure that Java is installed download selenium from here, unzip and run the following in the directory that it is extracted to:

cd selenium-remote-control-1.0-beta-1
cd selenium-server-1.0-beta-1
java -jar selenium-server.jar -interactive

Once this is running you can start scripting with PHP to get Selenium to do anything that you want. Once you are done make sure that you exit the Selenium server by running the “exit” at the prompt.

I’m sorry about the format of this post, its been a while since I have used Selenium and I’m quite excited about it. If you have any questions about Selenium post them here and I will try to answer them for you.