5 Replies Latest reply: Apr 22, 2013 7:59 AM by Pierre L.
Uproooar Level 1 Level 1 (0 points)

The aim is to assign a shortcut for copying the artist and name of currently playing or selected song from iTunes to the clipboard.


How it can be done?


MacBook Pro, OS X Mountain Lion (10.8.2)
  • Camelot Level 8 Level 8 (46,440 points)

    I usually recommend not manipulating the clipboard via AppleScript - not because it can't be done (it can), but because there are usually better options.

     

    In any case, since I don't know what you're ultimately trying to do...

     

    tell application "iTunes"

              if player state is playing then

                        set TA to artist of (get current track)

                        set TN to name of (get current track)

      set the clipboard to TA & " - " & TN

              end if

    end tell

     

    The issue is assigning this to a key shortcut, which AppleScript can't do on its own.

  • Pierre L. Level 5 Level 5 (4,140 points)

    You could use FastScripts (free for up to 10 keyboard shortcuts) to assign the script to a key shortcut.

  • Uproooar Level 1 Level 1 (0 points)

    Case #1 – Copy current track's "Artist Name - Track Title" to the clipboard by pressing shortcut.

     

    Applescript + FastScripts do it but I don't want an extra app in Login Items.

     

    Case #2 – Copy selected tracks' "Artist Name - Track Title" to the clipboard by pressing shortcut.

     

     

    That's what I have in clipboard after pressing cmd + c (unnecessary info: album, duration, etc.)

    Screen Shot 2013-04-22 at 20.58.04.png

     

    Thats what I want in clipboard after pressing shortcut (e.g., alt + c or cmd + c if possible)

    Screen Shot 2013-04-22 at 20.57.09.png

  • Camelot Level 8 Level 8 (46,440 points)

    I'm not sure what you're saying here.

     

    I've already provided an example of how to extract the data you want, and I've already explained that AppleScript cannot launch/respond to arbitrary key presses on its own - for that you need some other software.

  • Pierre L. Level 5 Level 5 (4,140 points)

    Try this:

     

    set theInfos to ""

    tell application "iTunes"

        repeat with thisItem in selection

            set theInfos to theInfos & artist of thisItem & " - " & name of thisItem & return

        end repeat

    end tell

    set the clipboard to theInfos