• Apfeltalk ändert einen Teil seiner Allgemeinen Geschäftsbedingungen (AGB), das Löschen von Useraccounts betreffend.
    Näheres könnt Ihr hier nachlesen: AGB-Änderung
  • Was gibt es Schöneres als den Mai draußen in der Natur mit allen Sinnen zu genießen? Lasst uns teilhaben an Euren Erlebnissen und macht mit beim Thema des Monats Da blüht uns was! ---> Klick

GeekTool: iTunes-Scripte

Teo

Schweizer Glockenapfel
Registriert
09.09.08
Beiträge
1.380
Ich versuche mich gerade an GeekTool (Version 3 RC5) und habe mir einige Scripts aus dem Netz zusammengesucht, mit denen ich Titel, Interpret und Album des aktuell in iTunes gespielten Songs anzeigen lassen möchte. Ausserdem würde ich gerne das jeweilige Artwork anzeigen lassen. Eins nach dem anderen.

Zunächst zum kleineren Problem: Mit folgendem Script lasse ich den Text für Interpret, Album und Titel ausgeben. Leider wird iTunes immer automatisch neu gestartet, wenn ich das Script über GeekTool laufen habe und iTunes beende. Wo steckt der Fehlerteufel?
Code:
tell application "System Events"
	set powerCheck to ((application processes whose (name is equal to "iTunes")) count)
	if powerCheck = 0 then
		return ""
	end if
end tell
tell application "iTunes"
	try
		set playerstate to (get player state)
	end try
	if playerstate = paused then
		set trackPaused to " (Pausiert)"
	else
		set trackPaused to ""
	end if
	if playerstate = stopped then
		return " "
	end if
	set trackID to the current track
	set trackName to the name of trackID
	set theStream to the current stream title as text
	if theStream is not "missing value" then
		set totalData to "Stream:	" & trackName & trackPaused & "
Titel:		" & theStream
	else
		set artistName to the artist of trackID
		set albumName to the album of trackID
		set totalData to "Titel:			" & trackName & trackPaused & "
Interpret:	" & artistName & "
Album:		" & albumName
	end if
	return totalData
end tell

Das zweite Problem betrifft das Script für die Cover. Ich habe diverse Anleitungen ausprobiert, komme aber leider nicht zum Ziel.
Beim manuellen Ausführen des folgenden Scripts erhalte ich die Fehlermeldung
error "\"Macintosh HD:Users:User:pictures:iTunes Artwork:From iTunes:albumArt.pict\" kann nicht in Typ file specification umgewandelt werden." number -1700 from "Macintosh HD:Users:User:pictures:iTunes Artwork:From iTunes:albumArt.pict" to file specification

Code:
(* Set Defaults and Loctions *)

set iTunesArtworkFolder to ((path to home folder) as text) & "Pictures:iTunes Artwork:"
-- Artwork Folder

set DefaultArtwork to ((path to home folder) as text) & "Pictures:iTunes Artwork:Default:albumArt.tif"
-- When there's no artwork or iTunes isn't running. This is a transparent TIFF.

set DefaultFolder to ((path to home folder) as text) & "Pictures:iTunes Artwork:Default:"
-- Default Folder

set FromiTunesFolder to ((path to home folder) as text) & "Pictures:iTunes Artwork:From iTunes:"
-- Where iTunes saves the Artwork

set ArtworkFromiTunes to FromiTunesFolder & "albumArt.pict" as file specification
-- The Artwork from iTunes

set AlbumArtwork to (path to home folder) & "Pictures:iTunes Artwork:albumArt.tif" as string
-- The Album Artwork

set UnixAlbumArtwork to the quoted form of POSIX path of AlbumArtwork
-- Unix path to the Album Artwork


(* Check if iTunes is running. *)

tell application "System Events"
	if exists process "iTunes" then
		try
			
			(* Get Artwork From iTunes *)
			tell application "iTunes"
				set aLibrary to name of current playlist -- Name of Current Playlist
				set aTrack to current track
				set aTrackArtwork to null
				
				(* Is there any Artwork? *)
				if (count of artwork of aTrack) ≥ 1 then
					set aTrackArtwork to data of artwork 1 of aTrack
					set fileRef to (open for access ArtworkFromiTunes with write permission)
					try
						set eof fileRef to 512
						write aTrackArtwork to fileRef starting at 513
						close access fileRef
					on error errorMsg
						try
							close access fileRef
						end try
						error errorMsg
					end try
					
					(* Convert to Tiff *)
					tell application "Finder" to set creator type of ArtworkFromiTunes to "????"
					
					tell application "Image Events"
						set theImage to open ArtworkFromiTunes
						save theImage as TIFF in iTunesArtworkFolder & "albumArt.tif" with replacing
					end tell
					
				else
					
					(* If there's no Artwork use the Blank Arwork. *)
					tell application "iTunes"
						if (count of artwork of aTrack) < 1 then
							set aTrackArtwork to DefaultArtwork
							
							
							set unixDefaultFolder to the quoted form of POSIX path of DefaultFolder
							set unixiTunesArtworkFolder to the quoted form of POSIX path of iTunesArtworkFolder
							
							do shell script "ditto -rsrc " & unixDefaultFolder & space & unixiTunesArtworkFolder
							
						end if
					end tell
				end if
			end tell
		end try
		
	else
		if (exists process "iTunes") is false then
			
			(* If itunes isn't running use the Blank Artwork *)
			tell application "Finder"
				set unixDefaultFolder to the quoted form of POSIX path of DefaultFolder
				set unixiTunesArtworkFolder to the quoted form of POSIX path of iTunesArtworkFolder
				
				do shell script "ditto -rsrc " & unixDefaultFolder & space & unixiTunesArtworkFolder
			end tell
			
		end if
	end if
end tell

Wäre sehr nett, wenn mir geholfen werden könnte.
 

LittlePixel

Strauwalds neue Goldparmäne
Registriert
09.07.08
Beiträge
641
Hallo,

zu 1:

Code:
tell application "System Events"
	set apps to every process whose bundle identifier is equal to "com.apple.iTunes"
	if (apps is {}) then return
end tell

zu 2:

Du möchtest das Cover vom aktuellen Titel? Dann geht Dich die Dateiebene nichts an ;)
Die Coverbenennung ist sehr komplex und auf die Persistent ID zurückzuführen.

So holst Du das Cover:

Code:
set artData to artwork 1 of current track

bzw:

Code:
set artData to data of artwork 1 of current track

Du mußt natürlich auch überprüfen, ob überhaupt ein Cover vorhanden ist.


Allgemein:

Du fragst ganz oft den Pfad zum Heimatverzeichnis ab. Sichere Dir den Pfad in einer Variable, dann brauchst Du das nicht jedes Mal berechnen lassen.
Das gilt für alle Berechnung, die Du mehr als ein Mal benötigst.

Viele Grüße
 

Teo

Schweizer Glockenapfel
Registriert
09.09.08
Beiträge
1.380
Vielen Dank!
Leider konnte ich das Problem mit deinen Codeschnippslen nicht lösen.

Ich muss sagen, dass ich bisher noch nie mit diesen Scripten hantiert habe. Ich verstehe das wenigste von dem, was dort ausgeführt wird wirklich.

Bei dem Coverscript wird wohl im Groben folgendes gemacht:
Das Cover wird abgefragt und als Bilddatei exportiert. Diese Datei wird dann mit einem zweiten Geeklet auf dem Bildschirm ausgegeben. Ausserdem sorgt das erste Script noch dafür, dass ein transparente Bild angezeigt wird, solange iTunes nicht läuft.
 

sch1zm

Jonagold
Registriert
12.09.07
Beiträge
18
habe das selbe problem. würde gerne das itunes cover per applescript auslesen um es in einem anderen programm anzeigen zu können. finde allerdings keinen funktionierenden befehl.
 

LittlePixel

Strauwalds neue Goldparmäne
Registriert
09.07.08
Beiträge
641
Hallo,

Du mußt konkreter werden.
Wie Du an das Cover kommst steht oben.

Viele Grüße
 

sch1zm

Jonagold
Registriert
12.09.07
Beiträge
18
ich möchte, auch wenn es vll unsinnig klingt, das cover auslesen und in einem java-programm wieder anzeigen lassen.
das ganze mache ich, indem ich in meinem programm das terminal öffne und einen as-befehl "eingebe". dieser liefert mir dann meine daten.
um zb die spielzeit auszugeben, öffne ich das terminal und geben folgenden befehl ein: tell app \"iTunes\" to get time of current track
das funktioniert soweit auch. das gleiche möchte ich nun mit dem aktuellen cd-cover machen.

brauchst du noch mehr informationen?