Archive for the ‘Knacks’ Category

Fix the home and end keys in Firefox with Keyconfig and Vimperator

Somme funny man thought that it would be good to screw up the behavior of home and end keys in firefox on Mac. Nobody knows why and everybody is complaining. Also, the same genius have made the ⌘→ and ⌘← commands navigate in history instead of doing what they do in every other application which is “move to the end or beginning of the line”. Oh well..

Luckily there IS a solution for this. The extension keyconfig will fix half of the problem get the keyconfing extension here and disable the incriminating keys. Many thanks to the author.

Now you have working command keys. As for the home and end key, I fixed my problem in vimperator, since it is an extension I use on all of my firefoxes. Basically the idea is to remap home and end (along with +shift variants) so they fire off the command+arrow commands.

Here is the code, enjoy :

imap <Home> <M-Left>
imap <End> <M-Right>
imap <S-End> <M-S-Right>
imap <S-Home> <M-S-Left>

Either run it in the vimperator command line and do a :mkvimperatorrc! or put it directly into your configuration file.

Push irssi away messages to your iPhone

Using irssi for IRC is quite a must. Add some bitlbee sweetness and you have everything you need for your instant messaging needs. With a handy ssh application like iSSH you will get to a cyborg state when you are always connected. Small problem arises when compared to other IM applications, like IMO, that is that there are no notifications available and you will probably miss a lot of conversations.

Fear not, however, for there is a solution for every problem.

Push notification application

First, you will need an application to get any push notification to your phone. There are several of them, I would recommend using the Push4. There is a free version if you want to test it first.

Once you have installed it and created an account go to your account settings on your website and go to My Account -> Settings -> Profile to get your API key. You can also make the application send you an e-mail with the key.

Some scripting

You will need to make two scripts to send the notifications. (You could manage with less, of course, but I am too lazy). First one is a bash script which uses curl to send a notification to your phone.

Here it is :

curl -d "user_credentials=YOUR_API_KEY" \
-d "notification[message]=$1" \
-d "notification[long_message]=$2" \
-d "notification[title]=New irssi notification" \
-d "notification[subtitle]=irssi message" \
-d "notification[long_message_preview]=$1" \
-d "notification[message_level]=2" \
-d "notification[silent]=0" \
-d "notification[action_loc_key]=OK" \
-d "notification[sound]=1" https://www.appnotifications.com/account/notifications.json

Do not forget to replace the YOUR_API_KEY by your real API key. You can test the script immediately, although it might not work for a few hours just after your Push4 account creation. Basically this script sends you a notifications with first parameter as short text preview and second as a long text (which can use HTML markup).

A second script is needed to parse the awaylog and send notifications using the first script.

#!/usr/bin/perl -n

use HTML::Entities;

if (/(\d+:\d+) (?:([#&][^ ]+)+:)?.*?\/.*?\/(.*?).g.8.*?e(yoz-y: )?(.*)/)
{
    $time = $1;
    $channel = $2;
    $sender = $3;
    $message = $5;

    $message =~ s/\\/:/g;
    $message =~ s/"/\\"/g;
    $message =~ s/[;&]/:/g;
    print `./irssi_notify.sh "$sender : $message at $time" "Message from <b>$sender</b> (<i>$channel</i>) at <b>$time</b> : $message"\n`;
}

Now, to clarify things a bit. What this script does is that it takes some input, and if it is in some format, /(\d+:\d+) (?:([#&][^ ]+)+:)?.*?\/.*?\/(.*?).g.8.*?e(YOURNICK: )?(.*)/, to be precise, it will parse it and send it via a notification. Note that this works if you did not play with your irssi theme too much, as the awaylog basically copies the format of public and highlight messages.

The (YOURNICK: )? part is optional, and it helps to remove the usual prefix of highlight messages.

I can not help you much with the regex, you have to find one on your own or you can use this script which basically takes anything in awaylog and sends it as it is (it works well and everywhere).

#!/usr/bin/perl -n

use HTML::Entities;

$message = encode_entities($_);
$message =~ s/\\/:/g;
$message =~ s/"/\\"/g;
$message =~ s/[;&]/:/g;
print `./irssi_notify.sh "$message" "$message"\n`;

Making it all work

Let us run the machine now. You will need to start another screen to run this (if somebody will help me with making a nohup version of the command I will gladly have it).

Run a terminal on your shell and run

screen bash
tailf ~/.irssi/away.log | perl irssi_notify.pl

Now detach the screen and you are on the roll.

Autocopy links of files uploaded to Dropbox public folder with a folder action

This tutorial is largely based on this post on the Dropbox forums, all credit on the script goes to the original author Christian G.

My contribution is that this script also invokes a Growl message (thus, you will need Growl installed) also, the # character is replaced by %23 (because Dropbox does not like it much)

Here goes the script :

on adding folder items to this_folder after receiving added_items
	try
		set the item_count to the number of items in the added_items
		if the item_count is equal to 1 then
			set theFile to item 1 of added_items
			set theRawFilename to ("" & theFile)

			set tid to AppleScript's text item delimiters
			set AppleScript's text item delimiters to ":"
			set theFileName to (text item 6 of theRawFilename) as text
			set AppleScript's text item delimiters to tid

			set theWebSafeFileName to switchText from theFileName to "%20" instead of " "
			set theWebSafeFileName to switchText from theWebSafeFileName to "%23" instead of "#"

			set theURL to "http://dl.dropbox.com/u/YOUR_DROPBOX_ID/" & theWebSafeFileName
			set the clipboard to theURL as text

			tell application "GrowlHelperApp"

				set the allNotificationsList to ¬
					{"Public URL"}

				set the enabledNotificationsList to allNotificationsList

				register as application ¬
					"CopyDropboxURL" all notifications allNotificationsList ¬
					default notifications enabledNotificationsList ¬
					icon of application "Dropbox"

				notify with name ¬
					"Public URL" title ¬
					"Dropbox Public Folder Updated" description ¬
					(theURL & " copied to clipboard.") application name "CopyDropboxURL"

			end tell
		end if
	end try
end adding folder items to

to switchText from t to r instead of s
	set d to text item delimiters
	set text item delimiters to s
	set t to t's text items
	set text item delimiters to r
	tell t to set t to item 1 & ({""} & rest)
	set text item delimiters to d
	t
end switchText

How to use this

First of allyou have to know your Dropbox user ID and change the YOUR_DROPBOX_ID to it. This is the number that appears after /u/ in your public Dropbox links.

Now open the apple script editor and save this script into Macintosh HD/Library/Scripts/Folder Action Scripts as CopyDropboxURL.scpt.

Next navigate to your Dropbox public folder in finder, right click (or ⌘-click) it. Choose Services->Folder Actions Setup… from the menu. In the menu that opens choose the CopyDropboxURL.scpt.

Enable system volume control for a generic USB device in Snow Leopard

This post is mainly targeted at people who have used an X-Fi USB audio card with their PCs on Windows or Linux. Many of us got a bad surprise when we plugged it into our shiny new Macs and we couldn’t even control the volume of the device through the system.

This particular problem is due to lack of dedicated drivers made by Creative. It seems that they only make OS X drivers for cards specially targeted at Macs.

Luckily there is a way to work around this limitation using a piece of software called Soundflower. The procedure is very simple, just follow the four steps here:

  1. Download and install SoundFlower (this might require a restart)
  2. Set Soundflower (2ch) as your audio output device (hint: you can option (⌥)-click your volume control icon in the menu)
  3. Launch Soundflowerbed (it was installed along with Soundflower)
  4. In the 2 channel device output options select your USB card.

And it is done, you can happily use your volume control buttons once again.

Set system output to Soundflower (2ch)

Set system output to Soundflower (2ch)

Set Soundflower output to your USB card

Set Soundflower output to your USB card

A nice dark color theme for QtCreator

Staring at long lines of code can get frustrating. Even more so if the said lines have ugly eye-hurting colors. I have been using the beautiful MacVim theme in Vim for some time now and it is quite awesome. However QtCreator, which I use for OpenViBE development, lacks such a theme. This problem was easily fixed though.

Here is a screenshot of a theme I have created and, because of the lack of creativity, named Gulf:

Gulf Qt Creator Theme

Gulf Qt Creator Theme

And here is the link for download:

Get ID3 tags right on your Cowon S9 with Linux

Those ID3 tags on Cowon can be pesky. Sometimes you do not see the embedded images, sometimes you see things like [11] instead of genres and if you are really unlucky you will not see any tags at all.

So, as a quick hint on how to get all of this right:

  1. Use EasyTAG (can be downloaded using your package manager in most distributions)
  2. In Settings → Preferences go to the ID3Tag settings and do the following
    • Check Automatically convert old ID3v2 tag versions
    • Check Write ID3v2 tag → Version 2.3
    • Uncheck Write ID3v1.x tag
  3. Edit tags of your files, be sure to re-save all files which appear in red in EasyTAG as they have probably different versions of ID3 tags
EasyTAG Cowon settings

A screenshot of the EasyTAG settings window

If you want to use images from the tags instead of the per-folder cover.jpg files you can use EasyTAG to include them in the tags as well. Bear in mind though that only jpeg files will be taken into account and only in mp3 files (no love for ogg users). Also for best effects use images of 272  x 272 pixels large.

Quick access to the last public url of a file in Dropbox

I got bored to search for the url after uploading a file to the Dropbox’s public folder. So I have hacked a quick shell script that takes the public url of the lastest file you uploaded to your public Dropbox folder and copies it to the clipboard. I thought I could share:

#!/bin/sh
DROPBOX="$HOME/Dropbox"

dropbox puburl "$DROPBOX/Public/`ls -1 -t $DROPBOX/Public | head -n 1`" | xclip

Now, on OS X I have a folder action which does the same thing automatically when a new file is uploaded. I will have to tinker with inotify and get it to work on Linux as well.

Global keyboard actions in Snow Leopard without third-party software

When I first got to use Mac OS X I have wondered whether it is possible to do stuff which I was used to do (more or less) easily on Linux. Among others there is the possibility to assign keyboard shortcuts to arbitrary actions (and especially shell scripts). I found several tutorials on how to do this, but they often include third party software like Quicksilver. Since I want to keep my system as vanilla as possible I was searching for a way to do it otherwise, and found it.

Introducing Services

Snow Leopard has this great thing called Services, which is a very simple to use way of creating very powerful actions in no time. Now, usually these are bound to a specific application or context, but they can be global.

Since it is much easier to explain something on an example, let us use a simple example. Following this article on how to pause iTunes for a short period of time.

Step 1:

  1. Open up the Automator.
  2. Create a New Service.
  3. In the ‘service receives selected’ drop-down box select no input in any application.
  4. In the left sidebar find Run AppleScript and drag it into the workflow
  5. Paste the code below on the place where it says (* Your script goes here *)
  6. Save the service as “Pause iTunes for 5 minutes”
tell application "iTunes"
    pause
    delay 300
    play
end tell

In the end the whole Automator window should look like this.

Automator service example

Automator service example

If you go to the current application’s menu now you should see your service in the Services sub-menu.

Step 2:

Now the only thing that remains is to add a keyboard shortcut for this service.

Open up System Preferences → Keyboard → Keyboard Shortcuts. In the left panel click on Services and then click on the + button under the right panel. In the following dialog choose:

  • Application : All Applications
  • Menu Title : Pause iTunes for 5 minutes
  • Keyboard Shortcut : F10

Following shortcut illustrates the result. Note that it is vital that the Menu Title chosen is exactly the same as the name under which you have saved the service.

Snow Leopard keyboard shortcut assignment

Snow Leopard keyboard shortcut assignment

All done, you can now enjoy launching your script anywhere, anytime by pressing F10.