• Apfeltalk ändert einen Teil seiner Allgemeinen Geschäftsbedingungen (AGB), das Löschen von Useraccounts betreffend.
    Näheres könnt Ihr hier nachlesen: AGB-Änderung
  • Viele hassen ihn, manche schwören auf ihn, wir aber möchten unbedingt sehen, welche Bilder Ihr vor Eurem geistigen Auge bzw. vor der Linse Eures iPhone oder iPad sehen könnt, wenn Ihr dieses Wort hört oder lest. Macht mit und beteiligt Euch an unserem Frühjahrsputz ---> Klick

Dateiname aus markiertem in iTunes markiertem lied

seb9

Bismarckapfel
Registriert
04.12.07
Beiträge
144
moinmoin liebe apfelscripter,
ich habe mich gestern mal n Applescript gesetzt und ein bisschen losgelegt, ich habe folgendes vorhaben:
Ein Skript welches in iTunes markierte Dateien auf einen Wchseldatenträger kopiert und dabei folgendes Ordnerschema erstellt (Datenträger:Music:)(klar, der pfad ist immer so, und dann):Artist:Album: und hier dann das lied hinkopiert.
Ich bin schon begeistert , dass ich es geschafft habe mithilfe 2er Skripte die Ordnererstellung zu lösen (immerhin nach vielleicht 5 Stunden Applescript), ist bestimmt nicht "schön" programmiert, scheint aber zu funktionieren.
Das Problem ist nur, jetzt möchte ich den Dateinamen des objektes für das ich gerade die ordner erstellt habe herausfinden, nur mag er nicht, hier mal mein code, die Rot Markierte stelle ist das Problem:
Code:
property My_choices : {"Title"}
property separator : " - " -- this is what appears between items; try " " or tab (without quotes) also
-------------------------------------
global xx, yy, file_name, zz
property okflag : false
-- check if iTunes is running 
tell application "System Events"
	if (get name of every process) contains "iTunes" then set okflag to true
end tell
if okflag then
	
	tell application "iTunes"
		if selection is not {} then -- check for selection
			set sel to a reference to selection
			set len to (count items of sel)
			
			repeat with i from 1 to len -- every track in selection in order
				set xx to "" -- intialize holder
				
				my copy_to_xx(get artist of item i of sel)
				
				set yy to "" -- itialize holder
				
				my copy_to_yy(get album of item i of sel)
				
				
				
				--- Create Folder with the Name stored in xx(Artist Name)
				tell application "Finder"
					if exists folder ("Macintosh HD:Users:Name:Desktop:Ordner:" & xx as string) then (* does nothing if  folder exists *)
					else
						try
							make new folder at ("Macintosh HD:Users:Name:Desktop:Ordner:") with properties {name:xx as string}
						end try
					end if
				end tell
				set xx to xx & ":"
				-- Create a Folder with the Name stored in yy(Album Name)
				tell application "Finder"
					if exists folder (("Macintosh HD:Users:Name:Desktop:Ordner:" & xx as string) & yy as string) then
					else
						try
							make new folder at ("Macintosh HD:Users:Name:Desktop:Ordner:" & xx as string) with properties {name:yy as string}
						end try
					end if
				end tell
[COLOR="Red"]	set zz to ""
			my copy_to_zz(get ???filename??? of item i of sel)
			set zz to zz [/COLOR]
			end repeat
			
		else -- no selection
			my send_a_message_and_quit("No tracks have been selected.")
		end if
	end tell
end if

------------ Subs:
to copy_to_xx(c) -- routine to copy artist to xx
	copy xx & c to xx
end copy_to_xx

to copy_to_yy(c)
	copy yy & c to yy
end copy_to_yy

to copy_to_zz(c)
	copy zz & c to zz
end copy_to_zz


Der Rot markierte teil, der der Befehl get irgendwas. Oben habe ich artist-name, album-name etc. ja gut bekommen, aber wenn ich get filename benutze sagt mir appescript:
"Die Typen der Deskriptoren passen nicht."
Damit kann ich nicht so viel anfangen.
(heißt das soviel wie "das was ich dir da zurückgebe gehört einer anderen Klasse an" also wie als wollte man in c++ zum Beispiel eine integer in eine gleitkommazahl-variable schreiben?

die applescript hilfe und auch das internet konnten mir bis jetzt zwar immer weiterhelfen, in diesem fall finde ich aber nichts hilfreiches.

wäre toll wenn mir einer helfen konnte.
ich hoffe mei ansatz ist überhaupt geeignet um das zu machen, was ich will.
mfg
seb
 

Daisy

Uelzener Rambour
Registriert
14.01.06
Beiträge
366
Moin,

ich habe schon lange nix mehr für iTunes gescriptet - so weiss ich nicht, ob es vielleicht noch einen einfacheren Weg gibt, an den Dateinamen zu kommen - aber das hier habe ich ausprobiert und es scheint zu funktionieren:

Code:
tell application "iTunes"
	my lastComponent((location of (get item 1 of selection)) as string, ":")
end tell

to lastComponent(theString, theDelimiter)
	set {od, text item delimiters} to {text item delimiters, theDelimiter}
	set returnValue to text item -1 of theString
	set text item delimiters to od
	return returnValue
end lastComponent

- location liefert den kompletten pfad als alias
- as string macht einen string daraus
- und lastComponent() fischt sich das letzte durch ':' getrennte Textelement raus

ich hoffe, das hilft dir weiter - ansonsten - schau mal bei http://dougscripts.com - da gibt es jede Menge Anschauungsmaterial zum Thema iTunes-Scripting.

D.
 

Daisy

Uelzener Rambour
Registriert
14.01.06
Beiträge
366
.. ach so ja - da wäre mir noch eine andere Lösung eingefallen:

Code:
tell application "iTunes"
	get my fileNameOfAlias(location of (get item 1 of selection))
end tell

to fileNameOfAlias(theAlias)
	tell application "Finder" to return name of theAlias
end lastComponent
 

seb9

Bismarckapfel
Registriert
04.12.07
Beiträge
144
klasse, dann werde ich damit mal versuchen ein funktionierendes skript zu basteln.
Vielen Dank!!
 

Skeeve

Pomme d'or
Registriert
26.10.05
Beiträge
3.120
Den Finder mußt Du nicht bemühen:
Code:
to fileNameOfAlias(theAlias)
	return name of (info for theAlias)
end fileNameOfAlias
 

seb9

Bismarckapfel
Registriert
04.12.07
Beiträge
144
So mal ein kleines Update, die Grundfunktionen die ich zum Bespielen meines Mp3-Players aus iTunes heraus habe, funktioneiren schonmal:
Also Ordner Artist:OrdnerAlbum:File Erstellen und hinkopieren, falls selbiges nicht schon existiert.
hier ist das kleine Skript, danke und Skeeve und Daysy:

Code:
(* Export Selected Song List v1.1
AppleSript for iTunes
written by Doug Adams 
[email protected]

Get more free AppleScripts and info on writing your own
at Doug's AppleScripts for iTunes and SoundJam
http://www.malcolmadams.com/itunes/ *)
-------------------------------------

property My_choices : {"Title"}
property separator : " - " -- this is what appears between items; try " " or tab (without quotes) also
-------------------------------------
global xx, yy, file_name, zz
property okflag : false
-- check if iTunes is running 
tell application "System Events"
	if (get name of every process) contains "iTunes" then set okflag to true
end tell
if okflag then
	
	tell application "iTunes"
		if selection is not {} then -- check for selection
			set sel to a reference to selection
			set len to (count items of sel)
			
			repeat with i from 1 to len -- every track in selection in order
				set xx to "" -- intialize holder
				
				my copy_to_xx(get artist of item i of sel)
				
				set yy to "" -- itialize holder
				
				my copy_to_yy(get album of item i of sel)
				
				
				
				--- Create Folder with the Name stored in xx(Artist Name)
				tell application "Finder"
					if exists folder ("Macintosh HD:Users:Name:Desktop:probeordner:" & xx as string) then (* does nothing if  folder exists *)
					else
						try
							make new folder at ("Macintosh HD:Users:Name:Desktop:probeordner:") with properties {name:xx as string}
						end try
					end if
				end tell
				set xx to xx & ":"
				-- Create a Folder with the Name stored in yy(Album Name)
				tell application "Finder"
					if exists folder (("Macintosh HD:Users:Name:Desktop:probeordner:" & xx as string) & yy as string) then
					else
						try
							make new folder at ("Macintosh HD:Users:Name:Desktop:probeordner:" & xx as string) with properties {name:yy as string}
						end try
					end if
				end tell
				set yy to yy & ":"
				tell application "iTunes"
					set zz to my fileNameOfAlias(location of (get item i of sel))
				end tell
				tell application "Finder"
					if exists file (("Macintosh HD:Users:Name:Desktop:probeordner:" & xx as string) & yy as string) then
					else
						try
							duplicate (("Macintosh HD:Users:Name:Music:iTunes:iTunes Music:" & xx as string) & (yy as string) & zz as string) to (("Macintosh HD:Users:Name:Desktop:probeordner:" & xx as string) & yy as string)
						end try
					end if
				end tell
			end repeat
			
			--end if
		else -- no selection
			my send_a_message_and_quit("No tracks have been selected.")
		end if
	end tell
end if

------------ Subs:
to copy_to_xx(c) -- routine to copy artist to xx
	copy xx & c to xx
end copy_to_xx

to copy_to_yy(c)
	copy yy & c to yy
end copy_to_yy

to copy_to_zz(c)
	copy zz & c to zz
end copy_to_zz

to fileNameOfAlias(theAlias)
	return name of (info for theAlias)
end fileNameOfAlias