Skip to Content

Autoblog reviews all the hottest cars
AOL Tech

Filed under: How-tos, iTunes, Terminal Tips

Terminal Tip: "Now Playing" info from the command line

Have you ever wondered whether there was a command line way to check iTunes and determine which song is currently playing. The command-line osascript utility makes this an easy problem to solve. Osascript executes AppleScript commands from Terminal's command line and can run many of the same kinds of simple scripts you'd normally run in Script Editor. Here's a quick how-to to build a Now Playing command line utility.

  1. Launch Terminal.
  2. In Terminal, enter: touch nowplaying
  3. In Terminal, enter: open -e nowplaying
  4. In TextEdit, paste the following into nowplaying. The second line wraps here but should copy and paste correctly--at least it did when I tried it out.
    #! /bin/bash
    osascript -e 'tell application "iTunes" to if player state is playing then "Now Playing: " & name of current track & " - " & artist of current track'
  5. Save the file in TextEdit and close it.
  6. In Terminal, enter: chmod 755 nowplaying
  7. Open iTunes and start playing a song.
  8. In Terminal, enter: ./nowplaying

The script, when run, outputs the track name and artist.

% ./nowplaying
Now Playing: Everything I've Got - Iain Archer
%

Thanks Dave M

Update: For those of you who don't want to keep iTunes open:
#! /bin/bash
osascript -e 'tell application "System Events" to if ((name of processes) contains "iTunes") then do shell script ("osascript -e " & quoted form of ("tell application \"iTunes\" to if player state is playing then \"Now Playing: \" & name of current track & \" - \" & artist of current track" & ""))'

Reader Comments (Page 1 of 1)

Tip of the Day

Holding the Command key (aka the Apple key) and pressing Tab will cycle through your open applications. It's easier to Cmd-Tab if you are Copy (Cmd-C) and Pasting (Cmd-V) to and from various applications.


Follow us on Twitter!
TUAW [Cafepress]

Sponsored Links

Featured Galleries

DNC Macs
Macworld 2008 Keynote
Macworld 2008 Build-up
Google Earth for iPhone
Podcaster
AT&T Navigator Road Test
Bento for iPhone 1.0
Scrabble for iPhone
Tom Bihn Checkpoint Flyer Briefcase
Apple Vanity Plates
Apple booth Macworld 07
WorldVoice Radio
Quickoffice for iPhone 1.1.1
Daylite 3.9 Review
DiscPainter
Mariner Calc for iPhone
2009CupertinoBus
Crash Bandicoot Nitro Kart 3D
MLB.com At Bat 2009
Macworld Expo 2007 show floor
Apple Texas Hold 'Em

 

More Apple Analysis

AOL Radio TUAW on Stitcher