[AppleScript] Copy Script

flashi

Alkmene
Registriert
11.01.19
Beiträge
32
HI Leute,

ich habe mal ein einfaches Copy Script erstellt mit Abfrage ob das Script ausgeführt werden soll.

Ihr das Script.
main.scpt
Code:
try
    # FFmpeg Script Installer.app = Contents/Resources/applet.icns
    set theicon to alias ((path to me as text) & "Contents:Resources:applet.icns")
    display dialog "Should the FFmpeg script be installed?" buttons {"Yes", "No"} with title "ffmpeg" with icon theicon
    set DlogResult to result
    if button returned of result = "Yes" then
        # FFmpeg Script Installer.app = Contents/Resources/Stuff/FFmpeg.workflow
        set theFileFFmpegWorkflow to alias ((path to me as text) & "Contents:Resources:Stuff:FFmpeg.workflow")
        # FFmpeg Script Installer.app = Contents/Resources/Stuff/ffmpeg_output_format.txt
        set theFileFFmpegOutputFormatTxt to alias ((path to me as text) & "Contents:Resources:Stuff:ffmpeg_output_format.txt")
        # FFmpeg Script Installer.app = Contents/Resources/Stuff/ffmpeg_output_file_options.txt
        set theFileFFmpegOutputFileOptionsTxt to alias ((path to me as text) & "Contents:Resources:Stuff:ffmpeg_output_file_options.txt")
        # services = /Users/xxxx/Library/Services
        set theNewFolderServices to (path to services folder)
        # documents = /Users/xxxx/Documents
        set theNewFolderDocuments to (path to documents folder)
        tell application "Finder"
            activate
            duplicate theFileFFmpegWorkflow to theNewFolderServices with replacing
            duplicate theFileFFmpegOutputFormatTxt to theNewFolderDocuments with replacing
            duplicate theFileFFmpegOutputFileOptionsTxt to theNewFolderDocuments with replacing
        end tell
    else
        beep 3
    end if
end try

So wie es oben ist, erstelle ich dann die App mit den Script-Editor. Wir nennen es Zbs. FFmpeg Script Installer.app. Dann schliesse ich den Script-Editor. Jetzt klicke ich die FFmpeg Script Installer.app rechts an und wähle den Reiter Paketinhalt zeigen an. Dann erstelle ich den Ordner Stuff in
Contents/Resources

. Dort Kopiere ich dann die Dateien FFmpeg.workflow, ffmpeg_output_format.txt und ffmpeg_output_file_options.txt rein. Das war es. Jetzt kann man die FFmpeg Script Installer.app starten und es werden die Dateien in den jeweiligen Ordner kopiert wie im Script angegeben und wären für die FFmpeg.workflow dann /Users/xxxx/Library/Services und für die Dateien ffmpeg_output_format.txt, ffmpeg_output_file_options.txt wer es der Path
/Users/xxxx/Documents
. Die xxxx ist der User Name den man beim install von Mac OS X angeben musste.

Ihr noch das workflow Script und die 2 Text Dateien.

FFmpeg.workflow
Code:
on run {input, parameters}
    ########################################### Path 1/1 ###########################################
    set file_path_output_file_options to ((path to documents folder) & "ffmpeg_output_file_options.txt") as string
    set file_path_output_format to ((path to documents folder) & "ffmpeg_output_format.txt") as string
    set logPath_ffmpeg_video_created to (path to documents folder as string) & "ffmpeg_video_created.log"
    set logPath_ffmpeg_errors to (path to documents folder as string) & "ffmpeg_errors.log"
    set ffmpegPathExport to "export PATH=$PATH:/usr/local/bin; which ffmpeg"
    ########################################### Path 1/1 ###########################################
    ######################################## FFmpeg Check 1/1 ########################################
    try
        #set ffmpegPath to do shell script "export PATH=$PATH:/usr/local/bin; which ffmpeg"
        set ffmpegPath to do shell script ffmpegPathExport
    on error
        beep 1
        display dialog "Please install \"ffmpeg\" on /usr/local/bin/ and try again." with title "Could not find \"ffmpeg\"!" buttons {"OK"} default button 1
       
        return
    end try
    ######################################## FFmpeg Check 1/1 ########################################
    ########################################### Counter 1/4 #########################################
    set fcount to 0
    ########################################### Counter 1/4 #########################################
    ################################# Question if the script should be executed 1/1 ###############################
    display dialog "Should the script be executed?" buttons {"Yes", "No"} with title "ffmpeg"
    set DlogResult to result
    if button returned of result = "Yes" then
        try
            ##################################### Output File Option 1/1 ###################################
            #set file_path_output_file_options to ((path to documents folder) & "ffmpeg_output_file_options.txt") as string
            read file file_path_output_file_options
            ##################################### Output File Option 1/1 ###################################
            set output_file_options to result
            #################################### Output Format Option 1/1 ##################################
            #set file_path_output_format to ((path to documents folder) & "ffmpeg_output_format.txt") as string
            read file file_path_output_format
            set output_format to result
            #################################### Output Format Option 1/1 ##################################
            ##################################### Execute FFmpeg 1/1 ####################################
            repeat with i in input
                set fname to POSIX path of i
                set o to text 1 thru -5 of fname
                do shell script ffmpegPath & " -i " & quoted form of fname & " " & output_file_options & " " & quoted form of (o & ".") & output_format
                ####################################### Counter 2/4 #####################################
                set fcount to fcount + 1
                ####################################### Counter 2/4 #####################################
                ################################### Log File Video Created 1/1 ################################
                #set logPath_ffmpeg_video_created to (path to documents folder as string) & "ffmpeg_video_ created.log"
                try
                    set logFile to open for access file logPath_ffmpeg_video_created with write permission
                    write (date string of (current date) & " " & time string of (current date) & " -- " & ffmpegPath & " -i " & quoted form of fname & " " & output_file_options & " " & quoted form of (o & ".") & output_format & return) to logFile starting at eof
                    close access logFile
                    try
                        close access logFile
                    end try
                end try
                ################################### Log File Video Created 1/1 #################################
            end repeat
            ###################################### Execute FFmpeg 1/1 #####################################
            ######################################### Counter 3/4 #######################################
            display notification "Number of files converted: " & fcount with title "ffmpeg"
            ######################################### Counter 3/4 #######################################
            ##################################### Log File FFmpeg Error 1/1 ##################################
        on error errorMessage
            #set logPath_ffmpeg_errors to (path to documents folder as string) & "ffmpeg_errors.log"
            try
                set logFile to open for access file logPath_ffmpeg_errors with write permission
                write (errorMessage & return) to logFile starting at eof
                beep 2
                display dialog "An error has occurred! More is in the log file!" & logPath_ffmpeg_errors buttons {"OK"} with title "ffmpeg" default button 1
                close access logFile
            on error
                try
                    close access logFile
                end try
            end try
            ##################################### Log File FFmpeg Error 1/1 ##################################
        end try
    else
        beep 3
    end if
    ################################## Question if the script should be executed 1/1 ################################
    ############################################ Counter 4/4 ##########################################
    return fcount
    ############################################ Counter 4/4 ##########################################
end run


ffmpeg_output_format.txt
Code:
mp4


ffmpeg_output_file_options.txt
Code:
-threads 1 -preset fast -c:a aac -b:a 128k -c:v libx264 -vf scale=854:480

EDIT

Fehler in der FFmpeg.workflow korrigiert und FFmpeg.workflow.zip und FFmpeg Script Installer.app.zip ersetzt.
 

Anhänge

  • FFmpeg Script Installer.app.zip
    1 MB · Aufrufe: 0
  • FFmpeg.workflow.zip
    206,3 KB · Aufrufe: 1
Zuletzt bearbeitet: