AppleScript: iTunes mit vorgegebener Library öffnen

roedert

Aktives Mitglied
Thread Starter
Dabei seit
05.01.2011
Beiträge
12.150
Reaktionspunkte
3.316
Da ich mit mehreren iTunes-Libs arbeite wollte ich mir die Arbeit ein wenig erleichtern und für jede Lib ein AppleScript schreiben.
Kanne mich zwar mit Skripten und Programmieren aus - nicht jedoch mit AppleScript......

Laufendes iTunes beenden, Alt drücken, iTunes starten, Alt loslassen, "W" drücken für Library wählen ..... so weit bin ich gerade

Doch wie teile ich dem Dateiauswahldialog mit welche Lib er nun öffnen soll....

Wem muss ich in AppleScript was "tellen" ;)

Danke für jeden Denkanstoss.....


Code:
tell application "iTunes" to quit
tell application "System Events"
	key down option
	delay 1
	tell application "iTunes"
		activate
		delay 0.5
		tell application "System Events"
			key up option
		end tell
		activate
		tell application "System Events"
			keystroke "w"
		end tell
	end tell
end tell
 
Das wäre eine Möglichkeit ;)

tell application "Finder" to open alias ":pfad:iTunes Library.itl"
 
Hallo,

ist mein erster Beitrag in diesem Forum und dann gleich zu einem Thema, welches mich jetzt schon seit Stunden beschäftigt!
Ich würde auch gerne meine zwei getrennten iTunes Bibliotheken mit einem Applescript umschalten können, da ich die Musik im ganzen Haus verteile und nicht immer direkt vor dem meinem Mac sitze!
Am Liebsten wären mir zwei getrennte Scripts um die Bibliotheken direkt anwählen zu können, muss jedoch nicht unbedingt sein!

Das wäre eine Möglichkeit ;)

tell application "Finder" to open alias ":pfad:iTunes Library.itl"

Funktioniert leider nicht, da immer die letzte iTunes Bibliothek geöffnet wird!

Ich habe auch schon mit der "com.apple.itunes.plist" herumgespielt aber irgendwie komm ich nicht ganz dahinter!!

Gibt es hier jemanden der so ein Script erfolgreich im Einsatz hat???
 
Gibt es hier jemanden der so ein Script erfolgreich im Einsatz hat???

Ja, hier! :) Wechsel in iTunes einmal zu der iTunes-Library die sich nicht in der Standard-Location befindet, schließe iTunes, führe im Terminal:
Code:
defaults read com.apple.itunes 'alis:1:iTunes Library Location' | pbcopy
aus, und füge sodann den Inhalt der Zwischenablage in folgendem Codebeispiel ein:

Code:
property alternativeLibraryLocation : "[COLOR="#FF0000"]<Hier zwischen den Anführungszeichen einfügen>[/COLOR]"

property plistEntryForLibLocation : "com.apple.iTunes 'alis:1:iTunes Library Location'"



on switchToLibraryAtLocation_(theLibraryLocation)
	quitITunes()
	do shell script "defaults write " & plistEntryForLibLocation & " " & quoted form of theLibraryLocation
	launch application "iTunes"
end switchToLibraryAtLocation_


on resetITunesLibraryLocation()
	quitITunes()
	do shell script "defaults delete " & plistEntryForLibLocation
	launch application "iTunes"
end resetITunesLibraryLocation


on quitITunes()
	tell application "iTunes" to if it is running then quit it
	
	repeat 60 times
		if iTunes is running then
			delay 1
		else
			exit repeat
		end if
	end repeat
end quitITunes

Du kannst dann mit einem switchToLibraryAtLocation_(alternativeLibraryLocation) -Aufruf zu Deiner alternativen Library wechseln, und mit resetITunesLibraryLocation() zurückwechseln.
 
Danke für das aber:

Ich öffne alternativ Bibliothek, schließe iTunes, starte Terminal, gebe
Code:
[COLOR=#000000]defaults read com.apple.itunes 'alis:1:iTunes Library Location' | pbcopy[/COLOR]

ein und bekomme das wenn ich es einsetze

Code:
<00000000 01600002 00010f4d 6163426f 6f6b2050 726f2053 53440000 00000000 00000000 0000cec6 6a98482b 00000006 1c900769 54756e65 73320000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000014 439ccf13 d1e70000 00000000 0000ffff ffff0000 09200000 00000000 00000000 00000000 00054d75 73696300 00100008 0000cec6 5c880000 00110008 0000cf13 c3d70000 0001000c 00061c90 00061c7f 000000b6 0002002d 4d616342 6f6f6b20 50726f20 5353443a 55736572 733a004d 61727469 6e3a004d 75736963 3a006954 756e6573 3200000e 00100007 00690054 0075006e 00650073 0032000f 0020000f 004d0061 00630042 006f006f 006b0020 00500072 006f0020 00530053 00440012 001a5573 6572732f 4d617274 696e2f4d 75736963 2f695475 6e657332 00130001 2f000015 0002000d ffff0000>

????????
 
Genau richtig. Ich hab noch vergessen, dass ich die iTunes-Variable als property definiert habe. Am Anfang des Skripts musst Du noch

Code:
property iTunes : application "iTunes"

einfügen.
 
Nochmal langsam, mein Code sieht jetzt so aus

Code:
[FONT=Lucida Grande]property [COLOR=#4f8f00]iTunes[/COLOR] : [COLOR=#0433ff]application[/COLOR] "iTunes"[/FONT]
[FONT=Lucida Grande]
[/FONT]
[FONT=Lucida Grande]property [COLOR=#4f8f00]alternativeLibraryLocation[/COLOR] : "<00000000 01600002 00010f4d 6163426f 6f6b2050 726f2053 53440000 00000000 00000000 0000cec6 6a98482b 00000006 1c900769 54756e65 73320000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000014 439ccf13 d1e70000 00000000 0000ffff ffff0000 09200000 00000000 00000000 00000000 00054d75 73696300 00100008 0000cec6 5c880000 00110008 0000cf13 c3d70000 0001000c 00061c90 00061c7f 000000b6 0002002d 4d616342 6f6f6b20 50726f20 5353443a 55736572 733a004d 61727469 6e3a004d 75736963 3a006954 756e6573 3200000e 00100007 00690054 0075006e 00650073 0032000f 0020000f 004d0061 00630042 006f006f 006b0020 00500072 006f0020 00530053 00440012 001a5573 6572732f 4d617274 696e2f4d 75736963 2f695475 6e657332 00130001 2f000015 0002000d ffff0000>"[/FONT]
[FONT=Lucida Grande]
[/FONT]
[FONT=Lucida Grande]property [COLOR=#4f8f00]plistEntryForLibLocation[/COLOR] : "com.apple.iTunes 'alis:1:iTunes Library Location'"[/FONT]
[FONT=Lucida Grande]
[/FONT]
[FONT=Lucida Grande]
[/FONT]
[FONT=Lucida Grande]
[/FONT]
[COLOR=#4F8F00][FONT=Lucida Grande][COLOR=#000000]on [/COLOR]switchToLibraryAtLocation[COLOR=#000000]:[/COLOR]theLibraryLocation[/FONT][/COLOR]
[COLOR=#4F8F00][FONT=Lucida Grande][COLOR=#000000]	[/COLOR]quitITunes[COLOR=#000000]()[/COLOR][/FONT][/COLOR]
[FONT=Lucida Grande]	[/FONT]
[COLOR=#4F8F00][FONT=Lucida Grande][COLOR=#000000]	[/COLOR][COLOR=#012fbe]do shell script[/COLOR][COLOR=#000000] "defaults write " & [/COLOR]plistEntryForLibLocation[COLOR=#000000] & " " & [/COLOR][COLOR=#812fdc]quoted form[/COLOR][COLOR=#000000] of [/COLOR]theLibraryLocation[/FONT][/COLOR]
[FONT=Lucida Grande]	[/FONT]
[COLOR=#0433FF][FONT=Lucida Grande][COLOR=#000000]	[/COLOR]launch[COLOR=#000000] [/COLOR]application[COLOR=#000000] "iTunes"[/COLOR][/FONT][/COLOR]
[COLOR=#4F8F00][FONT=Lucida Grande][COLOR=#000000]end [/COLOR]switchToLibraryAtLocation[COLOR=#000000]:[/COLOR][/FONT][/COLOR]
[FONT=Lucida Grande]
[/FONT]
[FONT=Lucida Grande]
[/FONT]
[COLOR=#4F8F00][FONT=Lucida Grande][COLOR=#000000]on [/COLOR]resetITunesLibraryLocation[COLOR=#000000]()[/COLOR][/FONT][/COLOR]
[COLOR=#4F8F00][FONT=Lucida Grande][COLOR=#000000]	[/COLOR]quitITunes[COLOR=#000000]()[/COLOR][/FONT][/COLOR]
[COLOR=#4F8F00][FONT=Lucida Grande][COLOR=#000000]	[/COLOR][COLOR=#012fbe]do shell script[/COLOR][COLOR=#000000] "defaults delete " & [/COLOR]plistEntryForLibLocation[/FONT][/COLOR]
[COLOR=#0433FF][FONT=Lucida Grande][COLOR=#000000]	[/COLOR]launch[COLOR=#000000] [/COLOR]application[COLOR=#000000] "iTunes"[/COLOR][/FONT][/COLOR]
[COLOR=#4F8F00][FONT=Lucida Grande][COLOR=#000000]end [/COLOR]resetITunesLibraryLocation[/FONT][/COLOR]
[FONT=Lucida Grande]
[/FONT]
[FONT=Lucida Grande]
[/FONT]
[COLOR=#4F8F00][FONT=Lucida Grande][COLOR=#000000]on [/COLOR]quitITunes[COLOR=#000000]()[/COLOR][/FONT][/COLOR]
[FONT=Lucida Grande]	tell [COLOR=#0433ff]application[/COLOR] "iTunes" to if it is [COLOR=#812fdc]running[/COLOR] then [COLOR=#0433ff]quit[/COLOR] it[/FONT]
[FONT=Lucida Grande]	[/FONT]
[FONT=Lucida Grande]	repeat 60 times[/FONT]
[FONT=Lucida Grande]		if [COLOR=#4f8f00]iTunes[/COLOR] is [COLOR=#812fdc]running[/COLOR] then[/FONT]
[FONT=Lucida Grande]			[COLOR=#0433ff]delay[/COLOR] 1[/FONT]
[FONT=Lucida Grande]		else[/FONT]
[FONT=Lucida Grande]			exit repeat[/FONT]
[FONT=Lucida Grande]		end if[/FONT]
[FONT=Lucida Grande]	end repeat[/FONT]
[COLOR=#4F8F00][FONT=Lucida Grande][COLOR=#000000]end [/COLOR]quitITunes[/FONT][/COLOR]

Stimmt das jetzt so?
Irgendwie kommt mir das Spanisch vor
 
Stimmt das jetzt so?
Irgendwie kommt mir das Spanisch vor

Sieht gut aus. Die Worte "launch" und "application" sind zusammengerutscht, aber das liegt wohl am copy-pasten aus dem Code heraus...

Und dann halt:

Code:
[COLOR=#000000][FONT=Verdana][B]my[/B] [/FONT][/COLOR][COLOR=#4F8F00][FONT=Verdana]switchToLibraryAtLocation[/FONT][/COLOR][COLOR=#000000][FONT=Verdana]:[/FONT][/COLOR][COLOR=#4F8F00][FONT=Verdana]alternativeLibraryLocation[/FONT][/COLOR]

bzw.

Code:
[COLOR=#4F8F00][FONT=Verdana]resetITunesLibraryLocation[/FONT][/COLOR][COLOR=#000000][FONT=Verdana]()[/FONT][/COLOR]
 
Sieht gut aus. Die Worte "launch" und "application" sind zusammengerutscht, aber das liegt wohl am copy-pasten aus dem Code heraus...

Das verstehe ich nicht, wie poste ich den Code richtig, ohne das alles verrutscht?

Und dann halt:

Code:
[COLOR=#000000][FONT=Verdana][B]my[/B] [/FONT][/COLOR][COLOR=#4F8F00][FONT=Verdana]switchToLibraryAtLocation[/FONT][/COLOR][COLOR=#000000][FONT=Verdana]:[/FONT][/COLOR][COLOR=#4F8F00][FONT=Verdana]alternativeLibraryLocation[/FONT][/COLOR]

bzw.

Code:
[COLOR=#4F8F00][FONT=Verdana]resetITunesLibraryLocation[/FONT][/COLOR][COLOR=#000000][FONT=Verdana]()[/FONT][/COLOR]

Sorry ich steh komplett auf dem Schlauch, muss ich das Script jetzt separat aufrufen oder noch etwas einbauen???
:hamma::hamma:
 
Habe jetzt verstanden!!
Danke!!

Nur noch wie poste ich den Code richtig ohne verrutschen??
 
Habe jetzt verstanden!!
Danke!!


Nur noch wie poste ich den Code richtig ohne verrutschen??
Gern - keine Ahnung. :p

Es kann übrigens nicht schaden, diese Zeile:

Code:
[COLOR=#012fbe][FONT=Lucida Grande]do shell script[/FONT][/COLOR][COLOR=#000000][FONT=Lucida Grande] "defaults delete " & [/FONT][/COLOR][COLOR=#4F8F00][FONT=Lucida Grande]plistEntryForLibLocation[/FONT][/COLOR]

in einen try-Block zu packen, d.h.:
Code:
[B]try[/B][FONT=Verdana]        
[COLOR=#012fbe][B]do shell script[/B][/COLOR] "defaults delete " & [COLOR=#4f8f00]plistEntryForLibLocation[/COLOR][/FONT]
[B]end [/B][B]try[/B]

Sonst bekommst Du bei (allerdings sowieso sinnlosem) mehrmaligem Hintereinanderausführen von resetITunesLibraryLocation() ​einen, wenn auch harmlosen, Fehler ausgespuckt...
 
Wenn Du den Knopf für Wysiwyg hier im Editor (oben links) deaktivierst, sollte nichts verrutschen...
 
Zurück
Oben Unten