Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

The Terminal, bindkey, and iTunes UNIX
I stopped using Butler and/or LaunchBar just to be more geeky by using the Terminal (don't tell me no one's ever done this before). I set up aliases fine, but encountered a problem setting up my 'Function keys (fkeys) to iTunes' functions. I knew to use bindkey, but couldn't find the special code for the fkeys anywhere -- you can't just put "F1."

After almost giving up, I stumbled upon a great Unix feature: Control-V. Press that in the Terminal and then hit any fkey, and it will give you the magic code to use, even pasting it if you're using vi. Then, put these lines (or something similar) in your ~/.cshrc (if using tcsh):
#Key bindings for iTunes
bindkey -c "^[OP" "sh /Users/your_user/scripts/previous"
bindkey -c "^[OQ" "sh /Users/your_user/scripts/playpause"
bindkey -c "^[OR" "sh /Users/your_user/scripts/next"
bindkey -c "^[OS" "sh /Users/your_user/scripts/tuneinfo"
You can use a different path to the scripts if you want. After that, you need to make those scripts. A sample one is:
echo "Play/Pause"
osascript <<ENDSCRIPT
  tell application "iTunes"
  set theCurrentTrack to the current track
  set theBand to the artist of theCurrentTrack as string
  set theSong to the name of theCurrentTrack as string
  return (theSong & " - " & theBand)
  end tell
For next and previous functions, just copy the first script and change playpause to next track and previous track, and the script must be named to match what you put in ~/.cshrc. Then log out, open a new terminal window, and voila! I am using these fkeys:
  • F1 - Previous Track
  • F2 - Playpause
  • F3 - Next Track
  • F4 - Track Info
These only work in the Terminal but this is OK, since other apps I use (namely World of Warcraft) use the fkeys.

[robg adds: I tested this one and it works as described (remember to make the scripts executable with chmod 755 script_name), but I'll stick with Butler -- I like having access to the keys from apps other than the Terminal.]
  • Currently 2.80 / 5
  You rated: 2 / 5 (5 votes cast)

The Terminal, bindkey, and iTunes | 5 comments | Create New Account
Click here to return to the 'The Terminal, bindkey, and iTunes' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
The Terminal, bindkey, and iTunes
Authored by: Azark on Dec 13, '04 10:29:48AM

I don't understand how using aliases could replace LaunchBar...
Am I missing something, or you have to remember the aliases to every apps or docs you use?

PB Ghz 1024MB Combo 10.3.6 /
G4 400 AGP 512MB 10.3.6 /
G4 400 AGP 768MB OSX Server 10.3.6

[ Reply to This | # ]
You mentioned WoW...
Authored by: Lectrick on Dec 13, '04 02:02:46PM

Forget iTunes. Instead, I think that Blizzard should make World of Warcraft applescriptable so I can write a bot to treadmill my leatherworking/skinning skills, lol

(I wonder how many online geek types are hunkered down in this game lately... it is very compelling)


In /dev/null, no one can hear you scream

[ Reply to This | # ]
The Terminal, bindkey, and iTunes
Authored by: readparse on Dec 13, '04 04:29:43PM

One minor point... this is not so much a thing as it is a shell thing... so it works in xterm as well, along with every other terminal environment.


[ Reply to This | # ]
The Terminal, bindkey, and iTunes
Authored by: erasei on Dec 14, '04 09:43:17AM
If you just want to control iTunes from hotkeys there is an awesome little PrefPane called SizzlingKeys that does a fabulous job in any app. I've had problems with just about all lauchers failing to execute the hotkey commands under certain conditions, but SK has worked every time. You can download it right from Apple at:

[ Reply to This | # ]

The Terminal, bindkey, and iTunes
Authored by: zane on Dec 14, '04 04:20:38PM
Control-v hey? That's pretty handy :)

You can also get these F-Key "magic codes" (as well as modified F-Keys, [ie: option-F1, shift-F1], and a bunch of other key codes for Home, End etc.) the long way via. the Terminal Inspector's "Keyboard" page.

You can get to the Terminal Inspector via. Terminal's Application Menu/Window Settings, or right/control click any terminal window and choose Window Settings. Then move to "Keyboard" in the drop down list, and browse the "Key Mappings" listing (which can also be modified/deleted).

Note that for key-binding you must prefix the listed codes with ^[ (carat, open-brace) which the control-v method as described in the above hint already does.

[ Reply to This | # ]