Displaying iTunes Album Art

Posted on
Mon Apr 02, 2012 3:16 pm
Dewster35 offline
Posts: 1030
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Displaying iTunes Album Art

Gotcha... I was going to say just have a smart playlist for now artwork and drag your "no artwork" image to make it that song's album art... that would be a way around that issue. That is if you're not going to take the time to add artwork by album manually...

Posted on
Mon Apr 02, 2012 4:36 pm
ckeyes888 offline
Posts: 2417
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Displaying iTunes Album Art

gtreece wrote:
The (selection) in iTunes will not be the same as the current track. A song is selected when it's highlighted, but any song could be playing.

That's why I went with:



Would it be possible to change the script that I have that is "working" to use your code?:
Code: Select all
set the_data to data of artwork 1 of current track


"Working" code:
Code: Select all
tell application "iTunes"
   set s to item 1 of (selection)
   set pd to data of first artwork of s
end tell
set fs to ("" & (path to desktop) & "MyArt.pict") as file specification
set rn to (open for access fs with write permission)
try
   set eof rn to 512
   write pd to rn starting at 513
   close access rn
on error err_mess
   close access rn
   error err_mess
end try

tell application "Finder"
   set file type of fs to "PICT"
   set creator type of fs to "????"
   activate
end tell

property pngFile : "/Library/Application Support/Perceptive Automation/iTunes.png"
property targetSize : 125

tell application "Image Events"
   launch
   set theImageReference to open fs
   -- create the png file
   scale theImageReference to size targetSize
   save theImageReference as PNG in pngFile with icon
   close theImageReference
end tell


Thanks,

Carl

Posted on
Mon Apr 02, 2012 4:58 pm
gtreece offline
Posts: 171
Joined: Sep 26, 2011

Re: Displaying iTunes Album Art

In theory, changing the 'tell iTunes' block to this would do it:

Code: Select all
tell application "iTunes"
   set pd to data of first artwork of current track
end tell


Your "working" script compiles for me, but doesn't run, based on the file specifications, so I can't test it without re-writing it.

Posted on
Mon Apr 02, 2012 6:41 pm
ckeyes888 offline
Posts: 2417
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Displaying iTunes Album Art

Really appreciate all the help.
I'll try that out later tonight.
Definitely hard to figure what works
and why.
Carl

Posted on
Tue Apr 03, 2012 12:04 am
ckeyes888 offline
Posts: 2417
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Displaying iTunes Album Art

Bingo, works beautifully. Many Thanks!!

Carl

Posted on
Fri Feb 01, 2013 9:47 pm
RogueProeliator offline
User avatar
Posts: 2501
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: Displaying iTunes Album Art

This is a bit old of a thread, but posting here just in case anyone else might be able to benefit... first of all, thanks to the previous posters for sharing their scripts, they definitely saved quite a bit of time in developing my own to better suit my needs!

What this script will do is to export the currently-playing tracks artwork, a placeholder image if no artwork is available, or a different placeholder if iTunes is not ready/running/whatever. If anyone is interested in using this in their own system, they should need only modify the properties up top unless further customization is wanted.

Code: Select all
-- configuration properties to set specific to your
-- own setup
property outputTempFN : "Library:Application Support:Perceptive Automation:Indigo 6:IndigoWebServer:images:iTunesCurrentAlbum.tiff"
property outputPNGFN : "Library:Application Support:Perceptive Automation:Indigo 6:IndigoWebServer:images:iTunesCurrentAlbum.png"
property noArtworkFN : "Library:Application Support:Perceptive Automation:Indigo 6:IndigoWebServer:images:iTunesNoArtworkAvailable.png"
property notPlayingFN : "Library:Application Support:Perceptive Automation:Indigo 6:IndigoWebServer:images:iTunesNotPlaying.png"
property targetSize : 256

-- main run routine
on run
   -- checks to ensure that itunes is running and available
   if my checkItunesIsActive() is false then
      -- uncomment below to show an error or add your own logging
      -- set opt to (display dialog "iTunes is not running." buttons {"OK"} default button 1 with title "Cannot proceed..." with icon 0 giving up after 30)
      my outputPlaceholderImage(notPlayingFN)
      return false
   end if
   
   -- ensure that itunes will respond, apparently some version will not if a modal dialog
   -- window is showing
   if my itunesIsNotAccesible() is true then
      -- uncomment below to show an error or add your own logging
      -- set opt to (display dialog "Close any utility windows that may be open in iTunes." buttons {"OK"} default button 1 with title "Cannot proceed..." with icon 0 giving up after 30)
      my outputPlaceholderImage(notPlayingFN)
      return false
   end if
   
   -- itunes should be available… attempt to process now
   tell application id "com.apple.iTunes"
      if (player state is playing) or (player state is paused) then
         if (artworks of current track exists) then
            -- the current track has artwork available, attempt to output
            -- that to a PNG now
            set artwork_data to (get raw data of first artwork of current track)
            my outputAlbumArtwork(artwork_data)
         else
            -- export the "no artwork available" file to the output
            my outputPlaceholderImage(noArtworkFN)
         end if
      else
         -- export the "not playing" artwork file to the output
         my outputPlaceholderImage(notPlayingFN)
      end if
   end tell
end run

-- this routine checks to see if iTunes is running
to checkItunesIsActive()
   tell application "System Events" to return (exists (some process whose name is "iTunes"))
end checkItunesIsActive

-- this routine ensures that itunes is responding to applescript commands
to itunesIsNotAccesible()
   try
      with timeout of 1 second
         tell application id "com.apple.iTunes" to get name of library playlist 1
      end timeout
   on error
      return true
   end try
   return false
end itunesIsNotAccesible

-- this routine will output the artwork data provided to the artwork
-- file specified in the properties at top
to outputAlbumArtwork(artwork_data)
   set tempFileHandle to (open for access outputTempFN with write permission)
   try
      tell application "System Events"
         write artwork_data to tempFileHandle starting at 0
         set file type of (outputTempFN as alias) to ".tiff"
      end tell
      close access tempFileHandle
      
      tell application "Image Events"
         launch
         set tempImageRef to open outputTempFN
         scale tempImageRef to size targetSize
         save tempImageRef as PNG in outputPNGFN with icon
         close tempImageRef
      end tell
   on error err_msg
      close access tempFileHandle
      -- log error message if desired
      -- set opt to (display dialog "Error: " & err_msg buttons {"OK"} default button 1 with title "Cannot proceed..." with icon 0 giving up after 30)
   end try
end outputAlbumArtwork

-- this rouitne will output the given filename, assumed to already be a PNG,
-- to the output filename defined in the properties up top
to outputPlaceholderImage(filename)
   set outputFileHandle to (open for access (outputPNGFN as alias) with write permission)
   try
      write (read (filename as alias)) to outputFileHandle starting at 0
      close access outputFileHandle
   on error err_msg
      close access outputFileHandle
      -- log error message if desired
      -- set opt to (display dialog "Error: " & err_msg buttons {"OK"} default button 1 with title "Cannot proceed..." with icon 0 giving up after 30)
   end try
end outputPlaceholderImage


Note that I would suggest testing it out running it directly (not through Indigo) to ensure all filenames and paths and all that good stuff is in order. I left my debug error messages in place but commented out. Should you have issues running it standalone, you might want to uncomment those for more details.

Adam

Posted on
Thu Aug 07, 2014 4:22 pm
Redrocker offline
Posts: 81
Joined: Jan 20, 2010

Re: Displaying iTunes Album Art

I know this is an old thread, but I'm just getting around to getting whole house audio working and control pages created for iTunes.

I have my Indigo (6) server running on a mac mini as headless in a wiring closet, easy enough. But here is where I run into issues trying to use album art in a control page: my iTunes server is running on an iMac, separate from the Indigo server. I can get the control page to display text and controls (Album, Playlist, Artist, etc.) and I can get the album art script to trigger and copy the album art into the images folder, on the iMac. But the control pages are looking for images on the mini.

Soooo, I'm sure this is a newbie Mac question, but I'm not well versed in network paths on OSX; how do I either copy the album art from the iMac "image" folder to the mini's "image" folder, OR, make the control page grab the image from the iMac?

Thanks in advance on a lesson in Mac network paths :D

~Mark
Indigo 2021.2

Posted on
Mon Mar 23, 2015 11:39 am
Korey offline
User avatar
Posts: 811
Joined: Jun 04, 2008
Location: Henderson, NV

Re: Displaying iTunes Album Art

RogueProeliator wrote:
This is a bit old of a thread, but posting here just in case anyone else might be able to benefit... first of all, thanks to the previous posters for sharing their scripts, they definitely saved quite a bit of time in developing my own to better suit my needs!

What this script will do is to export the currently-playing tracks artwork, a placeholder image if no artwork is available, or a different placeholder if iTunes is not ready/running/whatever. If anyone is interested in using this in their own system, they should need only modify the properties up top unless further customization is wanted.
Adam



Thanks for this Adam, it's exactly what I was looking to achieve!

:D :D :D

--
Korey

Posted on
Mon Mar 23, 2015 11:41 am
Korey offline
User avatar
Posts: 811
Joined: Jun 04, 2008
Location: Henderson, NV

Re: Displaying iTunes Album Art

Redrocker wrote:
I know this is an old thread, but I'm just getting around to getting whole house audio working and control pages created for iTunes.

I have my Indigo (6) server running on a mac mini as headless in a wiring closet, easy enough. But here is where I run into issues trying to use album art in a control page: my iTunes server is running on an iMac, separate from the Indigo server. I can get the control page to display text and controls (Album, Playlist, Artist, etc.) and I can get the album art script to trigger and copy the album art into the images folder, on the iMac. But the control pages are looking for images on the mini.

Soooo, I'm sure this is a newbie Mac question, but I'm not well versed in network paths on OSX; how do I either copy the album art from the iMac "image" folder to the mini's "image" folder, OR, make the control page grab the image from the iMac?

Thanks in advance on a lesson in Mac network paths :D


Here's an example of a path to display in a control page.

Code: Select all
file:///Library/Application Support/Perceptive Automation/Indigo 6/IndigoWebServer/images/iTunesCurrentAlbum.png

--
Korey

Posted on
Mon Jun 22, 2015 5:54 am
TOPS offline
User avatar
Posts: 169
Joined: Jun 17, 2015
Location: London, England

Re: Displaying iTunes Album Art

Hi Guys,

Regarding displaying Album Art, can anyone give me a step by step walkthrough on how to configure it please, I'm a new boy to Indigo but I can follow simple instructions (hopefully) if someone can help,

Thanks

Dave

Posted on
Sat Apr 02, 2016 10:08 am
Different Computers offline
User avatar
Posts: 2533
Joined: Jan 02, 2016
Location: East Coast

Re: Displaying iTunes Album Art

I'm probably way ahead of myself on this, since this is day 2 of the free trial for me, but could someone point me at the documentation for attaching applescripts to control pages?

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Sat Apr 02, 2016 10:18 am
RogueProeliator offline
User avatar
Posts: 2501
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: Displaying iTunes Album Art

I'm probably way ahead of myself on this, since this is day 2 of the free trial for me, but could someone point me at the documentation for attaching applescripts to control pages?

You don't attach AppleScript to the control pages for something like this -- rather, this is run in a trigger to generate the image. The control page then just points to that image. For this script, I have a trigger on the iTunes device for "Current Track Has Any Change".

AppleScript just runs as an action, so to have it run on a control page requires that it be in an action - such as when you click a button or text.

Adam

Posted on
Sat Apr 02, 2016 12:34 pm
Korey offline
User avatar
Posts: 811
Joined: Jun 04, 2008
Location: Henderson, NV

Re: Displaying iTunes Album Art

Different Computers wrote:
I'm probably way ahead of myself on this, since this is day 2 of the free trial for me, but could someone point me at the documentation for attaching applescripts to control pages?


This is what I use:

Applescript code:


Code: Select all

-- configuration properties to set specific to your
-- own setup
property outputTempFN : "Library:Application Support:Perceptive Automation:Indigo 6:IndigoWebServer:images:iTunesCurrentAlbum.tiff"
property outputPNGFN : "Library:Application Support:Perceptive Automation:Indigo 6:IndigoWebServer:images:iTunesCurrentAlbum.png"
property noArtworkFN : "Library:Application Support:Perceptive Automation:Indigo 6:IndigoWebServer:images:iTunesNoArtworkAvailable.png"
property notPlayingFN : "Library:Application Support:Perceptive Automation:Indigo 6:IndigoWebServer:images:iTunesNotPlaying.png"
property targetSize : 256

-- main run routine
on run
   -- checks to ensure that itunes is running and available
   if my checkItunesIsActive() is false then
      -- uncomment below to show an error or add your own logging
      -- set opt to (display dialog "iTunes is not running." buttons {"OK"} default button 1 with title "Cannot proceed..." with icon 0 giving up after 30)
      my outputPlaceholderImage(notPlayingFN)
      return false
   end if
   
   -- ensure that itunes will respond, apparently some version will not if a modal dialog
   -- window is showing
   if my itunesIsNotAccesible() is true then
      -- uncomment below to show an error or add your own logging
      -- set opt to (display dialog "Close any utility windows that may be open in iTunes." buttons {"OK"} default button 1 with title "Cannot proceed..." with icon 0 giving up after 30)
      my outputPlaceholderImage(notPlayingFN)
      return false
   end if
   
   -- itunes should be available… attempt to process now
   tell application id "com.apple.iTunes"
      if (player state is playing) or (player state is paused) then
         if (artworks of current track exists) then
            -- the current track has artwork available, attempt to output
            -- that to a PNG now
            set artwork_data to (get raw data of first artwork of current track)
            my outputAlbumArtwork(artwork_data)
         else
            -- export the "no artwork available" file to the output
            my outputPlaceholderImage(noArtworkFN)
         end if
      else
         -- export the "not playing" artwork file to the output
         my outputPlaceholderImage(notPlayingFN)
      end if
   end tell
end run

-- this routine checks to see if iTunes is running
to checkItunesIsActive()
   tell application "System Events" to return (exists (some process whose name is "iTunes"))
end checkItunesIsActive

-- this routine ensures that itunes is responding to applescript commands
to itunesIsNotAccesible()
   try
      with timeout of 1 second
         tell application id "com.apple.iTunes" to get name of library playlist 1
      end timeout
   on error
      return true
   end try
   return false
end itunesIsNotAccesible

-- this routine will output the artwork data provided to the artwork
-- file specified in the properties at top
to outputAlbumArtwork(artwork_data)
   set tempFileHandle to (open for access outputTempFN with write permission)
   try
      tell application "System Events"
         write artwork_data to tempFileHandle starting at 0
         set file type of (outputTempFN as alias) to ".tiff"
      end tell
      close access tempFileHandle
      
      tell application "Image Events"
         launch
         set tempImageRef to open outputTempFN
         scale tempImageRef to size targetSize
         save tempImageRef as PNG in outputPNGFN with icon
         close tempImageRef
      end tell
   on error err_msg
      close access tempFileHandle
      -- log error message if desired
      -- set opt to (display dialog "Error: " & err_msg buttons {"OK"} default button 1 with title "Cannot proceed..." with icon 0 giving up after 30)
   end try
end outputAlbumArtwork

-- this rouitne will output the given filename, assumed to already be a PNG,
-- to the output filename defined in the properties up top
to outputPlaceholderImage(filename)
   set outputFileHandle to (open for access (outputPNGFN as alias) with write permission)
   try
      write (read (filename as alias)) to outputFileHandle starting at 0
      close access outputFileHandle
   on error err_msg
      close access outputFileHandle
      -- log error message if desired
      -- set opt to (display dialog "Error: " & err_msg buttons {"OK"} default button 1 with title "Cannot proceed..." with icon 0 giving up after 30)
   end try
end outputPlaceholderImage
Attachments
Screen Shot 2016-04-02 at 11.32.09 AM.PNG
Screen Shot 2016-04-02 at 11.32.09 AM.PNG (68.04 KiB) Viewed 12492 times
Screen Shot 2016-04-02 at 11.32.13 AM.PNG
Screen Shot 2016-04-02 at 11.32.13 AM.PNG (81.33 KiB) Viewed 12492 times

--
Korey

Posted on
Sun Apr 03, 2016 10:50 am
Fishysan offline
Posts: 86
Joined: Feb 01, 2012

Re: Displaying iTunes Album Art

Thanks for the info all.

Anyone have any luck displaying Apple Music artwork? The scripts here don't show data when you are listening to Apple Music "Radio Station" like Beats, or the featured stations. The iTunes app of course displays the album artwork for the track playing but the AppleScript doesn't get the artwork. The Indio trigger does trigger with a track change on radio stations..

Thanks!

Posted on
Tue Apr 05, 2016 6:50 am
Different Computers offline
User avatar
Posts: 2533
Joined: Jan 02, 2016
Location: East Coast

Re: Displaying iTunes Album Art

This is very helpful.

Does anyone run iTunes on a different mac than Indigo? If so, how do you make the paths work?

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Who is online

Users browsing this forum: No registered users and 1 guest

cron