2015-10-20

Some custom iTunes shortcuts: show current track and toggle volume adjustment

I couldn't find any "native" iTunes way to do this and I thought this could help other people.

My goals:

  1. See some info on what's currently playing (singer name, song name...) from (mostly) anywhere.
  2. Change the volume adjustment of the current song from (mostly) anywhere. 
So I created some AppleScripts and Services using Automator and assigned keyboard shortcuts to them. 

The solutions:
  1.  Create a pop-up notification when keyboard shortcut is pressed.
    • AppleScript:

      to openInfo(name, num, artist, album, played, volume)
      display notification "" & artist & " (" & album & ")" subtitle "" & num & ": " & name & "(vol " & volume & ")"

      end openInfo

      tell application "iTunes"
      set sel to current track

      my openInfo(name of sel, track number of sel, artist of sel, album of sel, track count of sel, volume adjustment of sel)

      end tell
    • Service receives "no input" in "any application", run AppleScript:

      on run {input, parameters}
      set sAlias to "/Users/fcarasso/Apps/ShowCurrentItunesTrack.scpt"

      run script sAlias

      end run
    • My shortcut: command-F13
  2.  Toggle volume adjustment then show current and previous adjustment as a pop-up notification when keyboard shortcut is pressed.
    • AppleScript:

      tell
       
      application "iTunes"
      set toggles to {-50, -25, 0, 100, -50}

      set adj to volume adjustment of current track

      set newAdj to "not done"

      repeat with i from 1 to count toggles

      set low to toggles's item i

      set high to toggles's item (i + 1)

      if adj is low or (adj ≥ low and adj < highthen

      set (volume adjustment of current trackto (toggles's item (i + 1))

      set newAdj to volume adjustment of current track

      exit repeat

      end if

      end repeat

      display notification "New volume adjustement: " & newAdj & " (from " & adj & ")"

      end tell
    • Service receives "no input" in "any application", run AppleScript:

      on run {input, parameters}
      set scAlias to "/Users/fcarasso/Apps/ToggleVolumeAdjustment.scpt"

      run script scAlias

      return input

      end run
       
    • My shortcut: command-F14
The only time this seems to fail is when the focus is on Finder. Not ideal, but I can live with that.