Thursday, December 22, 2011

Applescript .exe handler for OSX

I needed a way to make all windows executables (.exe) open with wine on my OSX machines.

So here the Applescript code that does that. Paste it into the Applescript Editor, save it as an Application and then tell finder to open all .exe files with that. Done.


on run argv
set executable to (item 1 of argv)
set executable to posix_path(executable)
do shell script "/usr/local/bin/wine " & executable
end run

on open argv
set executable to (item 1 of argv)
set executable to posix_path(executable)
do shell script "/usr/local/bin/wine " & executable
end open

on posix_path(mac_path)
set mac_path to (mac_path as text)
set root to (offset of ":" in mac_path)
set rootdisk to (characters 1 thru (root - 1) of mac_path)
tell application "Finder"
if (disk (rootdisk as string) is the startup disk) then
set unixpath to "/" & (characters (root + 1) thru end of mac_path)
else
set unixpath to "/Volumes:" & mac_path
end if
end tell
set chars to every character of unixpath
repeat with i from 2 to length of chars
if item i of chars as text is equal to "/" then
set item i of chars to ":"
else if item i of chars as text is equal to ":" then
set item i of chars to "/"
else if item i of chars as text is equal to "'" then
set item i of chars to "\\'"
else if item i of chars as text is equal to "\"" then
set item i of chars to "\\" & "\""
else if item i of chars as text is equal to "*" then
set item i of chars to "\\*"
else if item i of chars as text is equal to "?" then
set item i of chars to "\\?"
else if item i of chars as text is equal to " " then
set item i of chars to "\\ "
else if item i of chars as text is equal to "\\" then
set item i of chars to "\\\\"
end if
end repeat
return every item of chars as string
end posix_path


The trickiest part was to find out how Applescript handlers work.
It still spits out some errors but it's working well enough.

Thursday, May 20, 2010

Smart(er) browser chooser

My problem is this:
I use multiple browsers. Firefox for the plugins; Chromium for the speed; Chrome for when Chromium breaks :) ; Opera for.... whatever.
Most desktop managers (I use Gnome) let you define your default browser. And most apps use that configuration when you click on a link in them.
The thing is that sometimes you already have a browser opened, and it's not your default browser.
For instants, sometimes I have Chromium running but my default browser is firefox.
If I click a link on the desktop or some app, I don't want it to launch firefox (with the "hundreds" of tabs I have opened in it's session)

So this is my solution. Place this code as an executable in /usr/bin/browser and configure Gnome to use it as the default browser.
#!/bin/bash
# The last option should be the default. To be used if none are running
BROWSERS=( firefox chromium-browser opera google-chrome x-www-browser )
for browser in ${BROWSERS[@]}; do
RUNNING=$(pgrep -u $USER -f $browser);
if [ "$RUNNING" ]; then
break
fi
done
COMMAND=$(type -P $browser);
exec $COMMAND "$@"

It goes through the list of browsers and if any of it's running, opens the clicked link in that one. If none are opened it launches the last one on the list.

Wednesday, January 20, 2010

Logitech Marble Trackball

I've struggled with the configuration of my Logitech Marble Trackball (the ambidextrous one with the 4 buttons) so many times that I decided to post it here. If for nothing else, for future reference.

HAL policy file:/etc/hal/fdi/policy/mouse-wheel.fdi

<?xml version="1.0" encoding="ISO-8859-1"?>
<deviceinfo version="0.2">
<device>
<match key="info.product" string="Logitech USB Trackball">
<merge key="input.x11_options.ButtonMapping" type="string">1 2 3 4 5 6 7 8 9</merge>
<merge key="input.x11_options.EmulateWheel" type="string">true</merge>
<merge key="input.x11_options.EmulateWheelButton" type="string">9</merge>
<merge key="input.x11_options.ZAxisMapping" type="string">4 5</merge>
<merge key="input.x11_options.XAxisMapping" type="string">6 7</merge>
<merge key="input.x11_options.Emulate3Buttons" type="string">true</merge>
</match>
</device>
</deviceinfo>

Right-handed configuration
left large button: left-click
left small button: scroll-wheel enabler
right small button: middle-click
right large button: right-click

execute when X starts:
/usr/bin/xinput set-button-map "Logitech USB Trackball" 1 9 3 4 5 6 7 8 2

Left-handed configuration
left large button: right-click
left small button: middle-click
right small button: scroll-wheel enabler
right large button: left-click

execute when X starts:
/usr/bin/xinput set-button-map "Logitech USB Trackball" 1 9 3 4 5 6 7 2 8

Since I use Gnome, I usually put these commands in a script and add it to Gnome's Startup Applications.

Saturday, October 17, 2009

Bought the toy, now I need to learn how to use it

OK, so I went a little crazy. It has been known to happen from time to time. This time I bought myself a camera. Not just any camera, a DSLR.
Getting down to the specifics. It's a Canon 500D body with a Canon 18-200mm IS lens. The set made a huge hole in my budget, but I think it'll be worth it. I tell myself it's a camera to last me a lifetime. We'll see.

Not having much free time during the work week, a proper field test of the camera had to wait until today. Here are a few of the photos I took. I still have a lot to learn about taking photographs with this kind of camera, but I think these four turned out OK.

Sunday, September 6, 2009

Note to Future-self: Apple keyboard in Linux (Alt. Alt Gr, Win/Command)

This is a note for myself, because I know one day I'm gonna be looking for this information again.
This blog seemed as god as any place to keep it.

At the present time I have an Apple keyboard. Not one of the new macbook-like keyboards, but on of the old clunky ones. Even if Apple call it a potuguese layout, it's still different from "regular" pt_PT keyboards.

So these are the xmodmap instructions to:

1 - Swap the Left Alt key with the Left Command key
remove Mod1 = Alt_L
remove Mod4 = Super_L
keycode 133 = Alt_L Meta_L Alt_L Meta_L Alt_L Meta_L
keycode 64 = Super_L
add Mod1 = Alt_L
add Mod4 = Super_L


2 - Swap the (Right) Alt Gr with the Right Command Key
remove Mod5 = ISO_Level3_Shift
keycode 134 = ISO_Level3_Shift NoSymbol ISO_Level3_Shift NoSymbol ISO_Level3_Shift
keycode 108 = Super_R NoSymbol Super_R NoSymbol Super_R
add Mod5 = ISO_Level3_Shift

Tuesday, August 18, 2009

HTC Magic and Android - first thoughts

A little over two weeks ago I bought a HTC Magic (black, don't think I could handle having a white phone) from my carrier TMN.
I didn't quite know what to expect from this phone. I had seen such polar opposite reviews all around the net, I was kind of lost. Decided to buy it just because it was on sale (half-price) and I can't resist a bargain...

It arrived while I was at YAPC::EU::2009 so I only started using not too long ago. However I'm confident that I can give a pretty fair (first) review at this point.

Disclaimer: I haven't done any kind of hacking to this phone (yet).

The touchscreen is pretty good, although it's not the very best out there. The OS is fast responding just as long as you don't have lots of applications running. Currently the battery last for two days (maximum) if I keep the WiFi, auto-sync and GPS enabled. Navigating the web is bearable, with this browser topping most browsers on Symbian smart-phones, but flash does not seem to work. Interesting enough it does come with Google Gears integrated. It does have Exchange compatibility, but I don't use it or have tested it. The 3 megapixel camera is OK, even if it doesn't have a flash (to which I was accustomed to by Nokia). Example picture 1 and picture 2. The on-screen keyboard it fair, chubby fingers may cause a problem. The spell correction makes it better but it's only available for English. There are other apps to replace the default keyboard (like BetterKeyboard) but haven't found one with a pt_PT dictionary yet.

One of the coolest features of this phone is the sync with some of Google's services. Your contacts and email's from GMail are synced to the phone. Your calendars on Google Calendar are also shared to the phone, however I've found this to be a bit unreliable.

The Android Market is very good but kind of a mess. I've found it difficult, sometimes, to choose between various (maybe too many) apps that claim to do the same thing.

In short... Is the HTC Magic a good phone? Yes, but it's not great. Is it worth the 400€ operators are asking for it? No! But I can live with myself having payed 250€ for it.
It's going to be my MID but I'm not gonna rely only on it.

Saturday, August 8, 2009

YAPC::EU::2009

During this year's vacations I got to go to YAPC::EU::2009, the yearly european conference about the Perl programming language. This year the conference was in Portugal (in the capital Lisbon), so it wasn't very expensive for me to go. Never having attended a conference of this magnitude I didn't know what to expect. Also, being (primarily) working with python for the last couple of years, I feared that most talks would be over my head.
However I found the conference to be very informal. All the speakers where very approachable and gave interesting (and accessible) talks.

Since I wasn't very "up-to-date" with Perl, I decided to go for the "Mastering Perl" training by brian d foy. My fears where unfounded. The training sessions where very easy-going and easy to understand. Learned alot about a wide range of tools and approaches in Perl (but also aplicable to other languages) programming.

There where some great moments that I will not soon forget. Hope they show up online. For now, here are some of the pictures and videos.

All I can say is Perl is very much alive and
Thanks Magda, Alberto and José for a great conference!