Archive for the ‘Tips’ Category

Control iTunes using Keyboard Shortcuts

Thursday, May 15th, 2008

At home I use iTunes on my Macbook to listen to music, and I’ve become a regular user of the keyboard shortcuts for controlling playback (pause/resume, previous track, next track, volume, etc). At work I can listen to my iTunes library using my portable drive, but as I’m using Windows and have a basic keyboard I don’t have these dedicated keys to control my music. This is frustrating because there’s even more need for this quick control at work, especially pausing the current song when my attention is required.

A few quick Google searches helped me to solve this issue using a small application called iTunes Hotkeys. You’ll need the free .NET framework before it’ll work but it sits in the system tray and responds to keyboard shortcuts such as (pause). It’s not quite a one key solution but it doesn’t take long for the shortcuts to become second nature. It will even launch iTunes for you if it’s not already running.

I’ve added a shortcut to Hotkeys on my desktop and assigned a keyboard shortcut to launch it. I could have it in Startup but I wont always want iTunes launching when I switch the workstation on.

Configuring an iTunes Backup & Archive Solution

Wednesday, May 14th, 2008

Since I bought my Macbook primarily for my media, I’ve been thinking about how I want to backup and archive my iTunes library. I’ve come up with a solution that works right for me, and once I’m moved and have set up a network in the new flat I’ll be able to make the finishing touches. This solution gives me a backup locally and remotely in a few simple steps.

First, I have bought a 320GB Western Digital Passport. I have set up an rsync that effectively mirrors my main iTunes library onto the external drive, which covers a “local” backup. I have also set up a seperate iTunes library on the drive, called ‘iTunes Archive’. To this I move the TV shows purchased through iTunes that I’ve watched, which means I can remove them from my main library and frees up space on my Mac.

For remote backup, I have an account with Mozy. Unfortunately Mozy don’t currently offer archiving so once something is removed from my Mac (or PC) it’s also removed from my Mozy backup. To solve this I will set up an rsync from my Mac to my PC that mirrors my iTunes library except the TV Shows and Movies folders, which will be a straight copy (no mirroring). This will mean that the PC will effectively have an archive of all of these items. This archive will then be uploaded to Mozy on the next run. Perfect!

The only concerns I can think of are:

  • If I make purchases on my PC rather than my Mac (not likely but possible of course)
  • until I have the rsync set up with the PC I have to make sure I have my ‘iTunes Archive’ on my Mac as well as the external drive (not a problem as I’m not too low on space yet).

I’m hoping that Apple announce improvements to iTunes at the upcoming WWDC in June, such as better management of TV Shows and Movies and perhaps a proper iTunes Server solution. By the way I am loving my Macbook Pro, and also really pleased with the WD Passport and can’t recommend either of them enough!

Creating a single line text file from DOS

Friday, April 25th, 2008

I recently had the need to write a batch file that wrote a single line of text to a file for processing by an application. I used the DOS command ‘ECHO’ and directed the output to file, however this wasn’t working and after a bit of troubleshooting I discovered that the resulting file couldn’t end with a new line.

At first I thought this could be a DOS/UNIX issue and ran a simple command-line application (DOS2UNIX) to convert my newlines to a format suitable for Unix based machines. Unfortunately this wasn’t good enough and I needed to find a way of removing the new line from my file. Eventually I found another simple application named CHANGE, which allows you to find and replace characters within files from the command line.

As the characters I needed to replace were a space and the carriage return/line feed I needed to be able to specify the characters as bytes. CHANGE.COM is able to do this, so the following command enabled me to remove the trailing new line:

CHANGE MYFILE.TXT 32,13,10 ""

The CHANGE.COM file can be downloaded from here.

Update: I found a Windows Script that will remove the line here, but have instead written a script that replaces the batch file.

Changing the current directory to a UNC path in DOS

Monday, February 18th, 2008

A useful tip in DOS and for those batch files is how to change the current directory to a network drive. You can use the NET USE command to map a network drive, but that requires knowing an available drive letter… The commands PUSHD and POPD allow you to immediately jump to the UNC path, temporarily mapping the first available drive letter. Use the command as follows:

PUSHD \\SERVERNAME\SHARE

The current directory will be changed to the route directory of a temporarily mapped network drive pointing at the share mentioned in the command. Use POPD on its own to unmap the drive and return to wherever you were before the PUSHD command was used. If you used PUSHD again before POPD then you begin to stack the drive mappings, and you simply POPD for each one of them when you’re done. Run PUSHD without any parameters to see the current details of the stack.

See Microsoft’s support site for the PUSHD command here.

Weekly Web Dev

Wednesday, February 13th, 2008

My flatmate (and twice contributor to TheDayToday) has started his own tech blog focusing on web development. He started it in January with some sort of encouragement from his employer - it’s refreshing that companies are acknowledging the existence of weblogs, and the benefits they can have to their staff’s development. Of course there’s also the cynical view that it’s a way to spy on your staff, but I think there’s a responsibility to the blogger to remain somewhat anonymous and to also set some boundaries before you begin writing - don’t dig your own grave! Anyway, he’s got some handy tips and best practices as well as news and reviews. Check it out here.

Schedule cPanelX database backups

Monday, October 8th, 2007

Yesterday my flatmate’s website host upgraded his version of MySQL and didn’t think to bring the tables to the new version. It’s easy to tell him that he should have a recent backup (he did, actually) but it got me thinking about a database I set up for CLEIS recently, which wasn’t being backed up at all…

Within about 20 minutes I had a daily backup running that will e-mail me the compressed SQL for the entire database. This uses a PHP file (stored outside the public_html directory for security reasons) that retreives and e-mails the database backup from the cPanelX control panel provided by my host.

Here is the contents of backup.php:

<?php
// Ignore all headers
#!/usr/local/bin/php -q

function get_db_file($db, $domain, $username, $password) {

  // Construct URL from segments
  $url = ‘http://’ . $username . ‘:’ . $password .’@’. $domain .’/getsqlbackup/’. $db .’.gz’;

  // Get the contents of the file
  return(file_get_contents($url));
}

function email_db_file($to, $from, $subject, $message) {
  global $db, $domain, $username, $password;
  $unique_sep = md5(uniqid(time()));

  // Set the e-mail headers
  $headers .= “From: $from\n”.
  “MIME-Version: 1.0\nContent-Type: multipart/mixed;boundary=\”$unique_sep\”;\n”.
  “charset=\”iso-8859-1\”\nContent-Transfer-Encoding: 7bit\n\n” .
  “–$unique_sep\n”.
  “Content-Type: text/plain; charset=\”iso-8859-1\”\n”.
  “Content-Transfer-Encoding: 7bit\n\n”.
  $message.”\n\n”.
  “–$unique_sep\n”.
  “Content-Type: gz; name=\”$db.gz\”\n”.
  “Content-Transfer-Encoding: base64\n”.
  “Content-Disposition: attachment\n\n”;

  // Use earlier function to get database file
  $file = get_db_file($db, $domain, $username, $password);

  // Attach the file to the e-mail
  $headers .= chunk_split(base64_encode($file)) . “–$unique_sep–\n”;

  // Send the e-mail
  if(mail($to, $subject, $message, $headers)) {
    return true;
  } else {
    return false;
  }
}

// Database name
$database_name = “db”;

// Domain name
// Make sure you include the port (:2082) for cPanelX.
$domain = “example.com:2082″;

// cPanelX username and password
$username = “username”;
$password = “password”;

// Address to send the backup file to
$email = “email@example.com”;

// Address the backup will be sent from
$from = “backups@example.com”;

// Call the function to send the e-mail
send_db_file($email, $from, $db .” Database Backup:”, “The scheduled backup of “. $db .” was performed at “. date(”g:i A F j, Y”));
?>

You’ll then need to set up a cron job in cPanelX to run the command php -q /home/[username] /backup.php on whatever schedule you need. You could even set up a second or third cron job to run on different schedules so that you can easily organise multiple generations of backups.

10 uses for a remote server

Friday, September 28th, 2007

My parents are planning on moving up to Scotland soon, and I’ve already agreed to set them up with PCs (possibly a Mac!) and a network once they’re settled into their new mansion house and what I get out of it is a remote server permanently connected to the ‘net for various uses such as an additional remote backup location, online storage, a proxy server, web server, ftp server, etc. I’ve not decided exactly what software to use on this machine, but it’ll probably be a Linux box (if you have any recommendations please post a comment!)

Anyway, I found this article on Lifehacker (great website!) listing 10 uses for a remote server. For those not wanting to click through, I’ve repeated the list below but without the explanations. I recommend clicking through!

  1. Back up your data
  2. Host a personal Wiki (blog or photo gallery)
  3.  Back up your Gmail (or any POP3 email)
  4. Synchronise your bookmarks (and documents)
  5. Mount a remote drive locally
  6. Run a version control system
  7. Build an Internet jukebox
  8. Set up a virtual private network
  9. Remote control BitTorrent transfers
  10. Securely proxy your web browsing traffic

Admittedly I hadn’t thought of backing up Gmail or mounting a local drive, and I’d probably do both. It’s all food for thought…

Firefox memory leak

Wednesday, September 19th, 2007

I’m a user and a fan of Mozilla’s Firefox browser. The argument that it’s more secure than IE is not one I use any more, as I have also been impressed with Microsoft’s latest browser. I think it comes down to personal preference, and I find the extensions capability of Firefox reason enough to stick with it. One thing that I would change in Firefox in an instant, however, is to fix the memory leak some call a ‘feature’. This is caused by the browser retaining a cache of viewed pages in the system’s memory for speedy recovery. Admittedly this isn’t a bad idea, but as it does this for each tab (and I use a lot of tabs) my current instance of the browser is almost at 500MB of memory usage, which means that a feature that has a minimal chance of actually being useful is actually having an affect on the free resources my machine has.

I’ve no doubt that if this memory is required by an application that Firefox releases it, but I find this has an affect on the browser itself and ultimately causes me to restart the application in order to return to a suitable response time.

According to several sources, you can fix this by restricting the amount of memory Firefox can use, but this has mixed results (some saying this is just a recommended restriction to the application). You can also turn off the caching, but this will almost certainly have an affect on your browsing experience - I’m guessing I use the back button more often than I realise. Another method is to enable a setting in the browser to flush memory whenever the application is minimized. This is the one I have now implemented and hopefully will start seeing a difference.

I have included instructions on implementing each solution below. I’d be interested to hear if anyone has much success. I’m also hopeful that Firefox 3 (due out soon) will address this long-standing issue.

Restrict memory allocation:

  1. In the address bar type about:config and press return.
  2. Right click on any value in the list and click New > Integer.
  3. Type browser.cache.memory.capacity for the preference name and click OK.
  4. Set the desired value in bytes that you want Firefox to use (for example 32768 bytes is equal to 32 megabytes).
  5. You will need to restart Firefox for the changes to take affect.

Disable caching:

  1. In the address bar type about:config and press return.
  2. Find the preference named browser.cache.memory.enable, right click it and select Toggle.
  3. The value should change to false.
  4. You will need to restart Firefox for the changes to take affect.

Trim memory usage on minimize:

  1. In the address bar type about:config and press return.
  2. Right click on any value in the list and click New > Boolean.
  3. Type config.trim_on_minimize for the preference name and click OK.
  4. Select the value to true.
  5. You will need to restart Firefox for the changes to take affect.

iPod Nano displaying wrong album art!

Thursday, September 6th, 2007

I originally posted about this on my old blog but it was a popular entry for people looking for a fix, and I’ve recently had the problem occur again, so I thought I’d repost.

I basically had no album art or the wrong album art being displayed on my iPod for a few weeks before I finally became curious and Google’d for a solution. Fortunately I wasn’t the first person to have this problem and Fonzo has managed to find the solution.

Basically you need to use the iTunes configuration option to disable artwork on the iPod and then update, which gets rid of all artwork. Then simple enable the artwork again and update. Simple as that!

By the way the problem seems to occur when you disconnect the iPod before it’s safe to do so.

Starting Control Panels applications with admin rights

Tuesday, August 14th, 2007

If you’re a frequent user of the runas command in Windows - which allows you to run an application as another user without needed to log on interactively - then you might find these following tips handy.

In most cases the second user has increased privileges, for example you might run a program installer under an admin account because the standard user does not have rights to install new applications. I therefore find it handy to have a shortcut to run a command line (cmd) with admin rights, so that anything I run from that command line will also have the elevated rights. I would also reccommend modifying the colours of the text/background of the cmd sessions so you can immediately see when you’re running as admin. Obviously this can be just as ‘dangerous’ as logging into the machine as admin, so you should take care.

Another really handy tip is to become familar with the names of the Control Panel applications so you can quickly run these with the increased rights. The syntax of the runas command is below, followed by a list of common Control Panel (cpl) application names. A full list of these can be found here.

runas /user:<user> "control <appname>"

Replace <user> with the administrator account username and <appname> with one of the following:

  • Add/Remove Programs: appwiz.cpl
  • Display Properties: desk.cpl
  • Firewall Properties: firewall.cpl
  • Internet Options: inetcpl.cpl
  • Network Connections: ncpa.cpl
  • Regional and Language Options: intl.cpl
  • System Properties: sysdm.cpl