An AppleScript-Problem

Hello all,

First of all I'd like to wish you some good days and a happy start into 2017!

Yesterday I started coding an AppleScript which organices my exported Whatsapp-Chats into a good folder structure. It is finished basically, but it throws an error that the second list index couldn't be read, though it exists, at least a debugging dialog shown it just fine!

Here is the script! Hope anyone can help me out here, I really need it! It containss some german terms, they're just folder names, some comments for myself  and a dialog text, so don't be confused for those who don't speak german smile

global mainfolder
global subfolder1
global subfolder2
global subfolder3
global filelist

--Hauptfunktion ausführen
main()
on main()
    set mainfolder to choose folder
    --Unterordner anlegen
    tell application "Finder"
        set subfolder1 to make new folder in mainfolder with properties {name:"Sprachnachrichten"}
        set subfolder2 to make new folder in mainfolder with properties {name:"Audiodateien"}
        set subfolder3 to make new folder in mainfolder with properties {name:"Videodateien"}
    end tell
    --Liste aller Dateien im Quellordner ermitteln
    tell application "System Events"
        set filelist to path of files in mainfolder
    end tell
    copy_voice_msgs()
    copy_audio_files()
    copy_video_files()
    set choice to button returned of (display dialog "Möchten Sie einen weiteren Whatsapp-Chat-Ordner organisieren?" buttons {"Ja", "Nein"} default button 1 cancel button 2 with title "Vorgang abgeschlossen!")
    if choice is "Ja" then
        main()
    end if
end main
on copy_voice_msgs()
    repeat with i from 1 to (count items in filelist)
        --Dateinamen des aktuellen Durchlaufs ermitteln, ist für den Kopiervorgang wichtig
        tell application "System Events"
            set currentfile to name of file (item i in filelist)
        end tell
        if currentfile begins with "." then
        else
            if currentfile ends with "opus" then
                move POSIX file item i in filelist to subfolder1
            end if
        end if
    end repeat
end copy_voice_msgs

on copy_audio_files()
    set audiotypes to {"wav", "mp3", "m4a", "aif"}
    repeat with i from 1 to (count items in filelist)
        --Dateinamen des aktuellen Durchlaufs ermitteln, ist für den Kopiervorgang wichtig
        tell application "System Events"
            set currentfile to name of file item i in filelist
        end tell
        if currentfile begins with "." then
        else
            --Dateiendungen ermitteln und Kopiervorgang für Audiodateien
            repeat with j from 1 to (count items in audiotypes)
                if currentfile ends with item j of audiotypes then
                    move POSIX file item i in filelist to subfolder2
                end if
            end repeat
        end if
    end repeat
end copy_audio_files

on copy_video_files()
    set videotypes to {"m4v", "mp4", "3gp", "avi"}
    repeat with i from 1 to (count items in filelist)
        --Dateinamen des aktuellen Durchlaufs ermitteln, ist für den Kopiervorgang wichtig
        tell application "System Events"
            set currentfile to name of file item i in filelist
        end tell
        if currentfile begins with "." then
        else
            --Dateiendungen ermitteln und Kopiervorgang für Audiodateien
            repeat with j from 1 to (count items in videotypes)
                if currentfile ends with item j of videotypes then
                    move POSIX file item i in filelist to subfolder3
                end if
            end repeat
        end if
    end repeat
end copy_video_files

Thanks in atvance and have a nice day,
gamefighter

_______________________________________________
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector

Reply via email to