• 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

Sortieren einer Liste

  • Ersteller iGuenni
  • Erstellt am

iGuenni

Gast
Hallo,
ich schreibe gerade ein AppleScript um MP3-Dateien per Drag&Drop in sortierter Reihenfolge auf einen MP3-Player zu kopieren.

Und mit der Sortierung habe ich ein Problem.

In dem angefügten Beispiel wird die Liste über die Variable the_files an die Funktion sort übergeben. In sort wird diese als a_list bearbeitet.
Nur ist a_list anscheinend leer.
Zur Kontrolle habe ich einige Dialog-Ausgaben eingebaut.

Ich hoffe hier kann mir jemand auf die Sprünge helfen.
Vielen Dank schonmal
iGuenni


Hier das Script:

property file_types : {"public.mp3"}
property last_location : path to "cusr"
property last_target : path to "cusr"

on open some_things
-- Dateiliste initialisieren
set the_files to {}
-- alle Dateien testen, ob sie hinzugefügt werden können
display dialog "2"
repeat with a_thing in some_things
set zeige to a_thing as alias
if type identifier of (info for a_thing) is in file_types then copy a_thing to the end of the_files
end repeat
repeat with a_test in the_files
display dialog "Liste unsortiert: " & (a_test as string)
end repeat
-- sortiere die Liste
set the_files to sort(the_files)
repeat with a_test in the_files
display dialog "Liste sortiert: " & (a_test as string)
end repeat
set target_name to choose folder name
repeat with an_alias in the_files
display dialog "Copy: " & an_alias as string
do shell script "cp -X " & quoted form of POSIX path of an_alias & " " & quoted form of POSIX path of target_name
end repeat
end open

to sort(a_list)
set oastid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ASCII character 10
display dialog "Sort: " & a_list
set a_list to (a_list as string)
set new_string to (do shell script "echo " & quoted form of a_list & " | sort -f")
set sort_list to (paragraphs of new_string)
set AppleScript's text item delimiters to oastid
return sort_list
end sort
 

iGuenni

Gast
Hallo nochmal,
ich denke ich habe den Fehler selber gefunden.

Die Zeile
if type identifier of (info for a_thing) is in file_types then copy a_thing to the end of the_files
muss lauten
if type identifier of (info for a_thing) is in file_types then copy a_thing as string to the end of the_files

Ich verstehe zwar nur noch nicht wo der Unterschied für die Variable the_files ist.
Vielleicht hat ja da noch jemand eine Antwort drauf.

iGuenni