Switching to #x application in the dock I would like to hit cmd+X to switch to (or launch, if it's not running) the #X application in the Dock, without hardconding that application.

I.e. if my third application in the dock is the Terminal, I hit cmd+3 and I switch to the terminal, but if I then move Adium to that position, cmd+3 automatically opens Adium.

Can this be done on OSX 10.8 (or 10.9)?

Even better, though that's not required, if in case I hit the combination of the already active application, it hides it instead.
You could save one AppleScript for clicking each Dock icon:

for i in {1..9};do echo 'tell application "System Events" to tell process "Dock" to click UI element '$i' of list 1'&gt;~/Library/Scripts/Focus\ Application\ $i.applescript;done

Then use FastScripts to assign shortcuts to the scripts.

I find it easier to just assign keyboard shortcuts for applications though.