• 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

on adding folder items: Alle Dateien erfassen

Stefan

Golden Delicious
Registriert
23.07.08
Beiträge
11
Hallo,
ich baue gerade an einem AppleScript (mein erstes), dass alle aif/wav Dateien die in einen Ordner kopiert werden automatisch nach FLAC komprimiert. Klappt für einzelne Dateien auch gut, aber wenn ich einen Ordner mit Dateien kopiere (egal ob ein normaler Ordner oder so GarageBand-Ordner wie meinsong.band) geht es nicht, da in dem Parameter der übergeben wird dann der Ordnername steht und nicht jede einzelne datei. Gibt es eine einfache Funktion mit der ich alle Dateien aus dem Ordner und allen Unterordnern bekomme? Das ich sowas ich mach kann wie:

if (filetype(Item) == FILETYPE_DIRECTORY) liste = allfiles(item);

Ich quäle mich ziemlich mit dem Schreiben dieser AppleScript-Romane, was einfacheres (egal was, hauptsache C-Syntax) kann man für solche Folder-Actions nicht verwenden?

Viele Grüße,
Stefan
 

schnydi

James Grieve
Registriert
08.01.06
Beiträge
137
Hier ein Beispiel um alle Dateien eines Ordner in eine Variable zu Packen:
Code:
tell application "System Events"
	set everyItems to files of folder "desktop" of home folder
end tell
Wenn du zum Beispiel mit allen Dateien eine bestimmte Aktion ausführen möchtest, dann musst du eine Repeat Schlaufe erstellen:
Code:
tell application "System Events"
	set everyItems to files of folder "desktop" of home folder
	repeat with i from 1 to (count of every item) of everyItems
		set myItem to item i of everyItems
		if file type of myItem is "JPEG" then
			-- eine Aktion ausführen
		else
			-- eine andere Aktion ausführen
		end if
	end repeat
end tell
Ja ein Roman ist dass dann alleweil!
Vielleicht hilft dir dass weiter.
 

Stefan

Golden Delicious
Registriert
23.07.08
Beiträge
11
Vielen Dank für deine Hilfe! Beim suchen des Codes zum Herausfinden ob es sich um einen Ordner handelt, bin ich auf eine Apple-Seite gestoßen die genau so eine Subroutine vorgestellt hat. Damit hab ich das dann hinbekommen.
Hier der Code als Droplet
Code:
property extension_list : {"aif", "aiff", "wav"}


on open these_items
    repeat with i from 1 to number of items in these_items
        set this_item to item i of these_items
        set the item_info to the info for this_item
        -- CHECK TO SEE IF THE ITEM IS AN AUDIO FILE OF THE ACCEPTED FILE TYPE
        if folder of the item_info is true then
            process_dir(this_item)
        else
            if (the name extension of the item_info is in the extension_list) and (alias of the item_info is false) and (folder of the item_info is false) then
                set filename_in to POSIX path of this_item
                set filename_out to filename_in & ".flac"
                do shell script "flac -7 --keep-foreign-metadata -V -o \"" & filename_out & "\" \"" & filename_in & "\" && rm \"" & filename_in & "\""
            end if
        end if
    end repeat
end open

on process_dir(dir)
    set these_items to list folder dir
    repeat with i from 1 to count of these_items
        set this_item to alias ((dir as Unicode text) & (item i of these_items))
        set the item_info to the info for this_item
        -- CHECK TO SEE IF THE ITEM IS AN AUDIO FILE OF THE ACCEPTED FILE TYPE
        
        if folder of the item_info is true then
            process_dir(this_item)
        else
            if (the name extension of the item_info is in the extension_list) and (alias of the item_info is false) and (folder of the item_info is false) then
                set filename_in to POSIX path of this_item
                set filename_out to filename_in & ".flac"
                do shell script "flac -7 --keep-foreign-metadata -V -o \"" & filename_out & "\" \"" & filename_in & "\" && rm \"" & filename_in & "\""
            end if
        end if
    end repeat
end process_dir
Das funktioniert so auch gut, aber andersrum (beim dekomprimieren) habe ich ein Problem: Wie kann ich überprüfe ob der Dateiname mit einer der Erweiterungen in der Liste endet, wenn die nun aif.flac, aiff.flac oder wav.flac lautet. Die normale Erweiterung lautet ja nur noch flac. Wie kann man das machen?

Viele Grüße,
Stefan
 

Stefan

Golden Delicious
Registriert
23.07.08
Beiträge
11
Ich habs noch hinbekommen, wenn auch kompliziert. Hier beide funktionsfähigen Scripts:

Komprimieren:
Code:
(* You may use this piece of code as you like - NO WARRENTY!
  You need to install flac (at least version 1.2.1) to /usr/bin (or change commands inside this script)
  You can get a universal OS X build of flac from rarewares: http://www.rarewares.org *)

property extension_list : {"aif", "aiff", "wav"}


on open these_items
    global n_f
    set n_f to 0
    repeat with i from 1 to number of items in these_items
        set this_item to item i of these_items
        set the item_info to the info for this_item
        -- CHECK TO SEE IF THE ITEM IS AN AUDIO FILE OF THE ACCEPTED FILE TYPE
        if folder of the item_info is true then
            process_dir(this_item)
        else
            if (the name extension of the item_info is in the extension_list) and (alias of the item_info is false) and (folder of the item_info is false) then
                set filename_in to POSIX path of this_item
                set filename_out to filename_in & ".flac"
                set shret to do shell script "flac -7 --keep-foreign-metadata -V -o \"" & filename_out & "\" \"" & filename_in & "\" && (rm \"" & filename_in & "\"; echo \"success\")"
                if (shret = "success") then
                    set n_f to n_f + 1
                end if
            end if
        end if
    end repeat
    display dialog "Es wurden " & n_f & " Audiodateien erfolgreich als FLAC verlustfrei komprimiert." buttons {"OK"} default button 1
end open

on process_dir(dir)
    global n_f
    set these_items to list folder dir
    repeat with i from 1 to count of these_items
        set this_item to alias ((dir as Unicode text) & (item i of these_items))
        set the item_info to the info for this_item
        -- CHECK TO SEE IF THE ITEM IS AN AUDIO FILE OF THE ACCEPTED FILE TYPE
        
        if folder of the item_info is true then
            process_dir(this_item)
        else
            if (the name extension of the item_info is in the extension_list) and (alias of the item_info is false) and (folder of the item_info is false) then
                set filename_in to POSIX path of this_item
                set filename_out to filename_in & ".flac"
                set shret to do shell script "flac -7 --keep-foreign-metadata -V -o \"" & filename_out & "\" \"" & filename_in & "\" && (rm \"" & filename_in & "\"; echo \"success\")"
                if (shret = "success") then
                    set n_f to n_f + 1
                end if
            end if
        end if
    end repeat
end process_dir
Dekomprimieren:
Code:
(* You may use this piece of code as you like - NO WARRENTY!
  You need to install flac (at least version 1.2.1) to /usr/bin (or change commands inside this script)
  You can get a universal OS X build of flac from rarewares: http://www.rarewares.org *)

property extension_list : {"aif", "aiff", "wav"}


on open these_items
    global n_f
    set n_f to 0
    set AppleScript's text item delimiters to "."
    repeat with i from 1 to number of items in these_items
        set this_item to item i of these_items
        set the item_info to the info for this_item
        -- CHECK TO SEE IF THE ITEM IS AN AUDIO FILE OF THE ACCEPTED FILE TYPE
        if folder of the item_info is true then
            process_dir(this_item)
        else
            set filename_in to POSIX path of this_item
            set filename_s to filename_in's text items
            set fscnt to number of items in filename_s
            set fscnt to fscnt - 1
            if (the name extension of the item_info is "flac") and (alias of the item_info is false) and (folder of the item_info is false) and (fscnt > 1) and (extension_list contains item fscnt of filename_s) then
                set flen to length of filename_in
                set filename_out to (get text 1 through (flen - 5) of filename_in)
                set shret to do shell script "flac -d --keep-foreign-metadata -V -o \"" & filename_out & "\" \"" & filename_in & "\" && (rm \"" & filename_in & "\"; echo \"success\")"
                if (shret = "success") then
                    set n_f to n_f + 1
                end if
            end if
        end if
    end repeat
    display dialog "Es wurden " & n_f & " FLAC-Audiodateien erfolgreich dekomprimiert." buttons {"OK"} default button 1
end open

on process_dir(dir)
    global n_f
    set these_items to list folder dir
    repeat with i from 1 to count of these_items
        set this_item to alias ((dir as Unicode text) & (item i of these_items))
        set the item_info to the info for this_item
        -- CHECK TO SEE IF THE ITEM IS AN AUDIO FILE OF THE ACCEPTED FILE TYPE
        if folder of the item_info is true then
            process_dir(this_item)
        else
            set filename_in to POSIX path of this_item
            set filename_s to filename_in's text items
            set fscnt to number of items in filename_s
            set fscnt to fscnt - 1
            if (the name extension of the item_info is "flac") and (alias of the item_info is false) and (folder of the item_info is false) and (fscnt > 1) and (extension_list contains item fscnt of filename_s) then
                set flen to length of filename_in
                set filename_out to (get text 1 through (flen - 5) of filename_in)
                set shret to do shell script "flac -d --keep-foreign-metadata -V -o \"" & filename_out & "\" \"" & filename_in & "\" && (rm \"" & filename_in & "\"; echo \"success\")"
                if (shret = "success") then
                    set n_f to n_f + 1
                end if
            end if
        end if
    end repeat
end process_dir
Vielen Dank,
Stefan