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
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
tell application "iTunes"
set pd to data of first artwork of current track
end tell
-- 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
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
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
file:///Library/Application Support/Perceptive Automation/Indigo 6/IndigoWebServer/images/iTunesCurrentAlbum.png
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?
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?
-- 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
Users browsing this forum: No registered users and 10 guests