GUI for simple script

Soldato
Joined
4 Oct 2019
Posts
3,233
Location
Queens Park - London
Hi all

I’m trying to take a video conversion script that I’ve added to Automator and create a GUI for it where I can select the videos I want to convert and the output file type from the interface to not have to go through 20+ videos one by one using a quick action script from the (right click) context menu.

I want to take 480P AVI video and convert it to 1080P MP4 X264 or X265.

I see many many Windows apps like BalenaEtcher which look great but are just a simple GUI to execute a scripted with custom variables.

Does anyone have any suggestions as to where I can learn to do this for OSX?

Thanks in advance.

Edit: I think I've found something that'll work for me. I'd still like to be able to create a GUI for my own scripts in the future though so please reply to this thread if you know how.

HBBatchBeast


maybe Tdarr will work too.


Right now, this is the script I'm running using quick action command added in Automator - I can only convert one video file at a time and select and highlighting more than 1 video doesn't convert all of them, just one.

Code:
originalFilePath=$1
uuid=$(uuidgen)
uuidFilePath="${originalFilePath%.*}-$i.mp4"

# Execute ffmpeg conversion
/opt/homebrew/bin/ffmpeg -i "$originalFilePath" -vf scale=1920x1080:flags=lanczos -c:v libx264 -preset slow -crf 21 "$uuidFilePath" > /dev/null 2>&1

# Check if ffmpeg was successful
if [ $? -eq 0 ]; then
    osascript -e 'display notification "Video conversion completed successfully" with title "Conversion Success"'
else
    osascript -e 'display notification "Video conversion failed" with title "Conversion Failure"'
fi
 
Last edited:
Code:
#!/bin/bash

for originalFilePath in "$@"; do
    uuid=$(uuidgen)
    uuidFilePath="${originalFilePath%.*}-${uuid}.mp4"

    # Execute ffmpeg conversion
    /opt/homebrew/bin/ffmpeg -i "$originalFilePath" \
        -vf scale=1920x1080:flags=lanczos \
        -c:v libx264 -preset slow -crf 21 \
        "$uuidFilePath" > /dev/null 2>&1

    # Check if ffmpeg was successful
    if [ $? -eq 0 ]; then
        osascript -e "display notification \"Converted: $(basename "$originalFilePath")\" with title \"Conversion Success\""
    else
        osascript -e "display notification \"Failed: $(basename "$originalFilePath")\" with title \"Conversion Failure\""
    fi
done

OR a gui

Code:
#!/bin/bash

# Ask user to pick multiple files
files=$(osascript -e 'set chosenFiles to choose file with multiple selections allowed
repeat with f in chosenFiles
    set contents of f to POSIX path of f
end repeat
return chosenFiles')

# Loop through each selected file
IFS=$'\n'
for originalFilePath in $files; do
    uuid=$(uuidgen)
    uuidFilePath="${originalFilePath%.*}-${uuid}.mp4"

    /opt/homebrew/bin/ffmpeg -i "$originalFilePath" \
        -vf scale=1920x1080:flags=lanczos \
        -c:v libx264 -preset slow -crf 21 \
        "$uuidFilePath" > /dev/null 2>&1

    if [ $? -eq 0 ]; then
        osascript -e "display notification \"Converted: $(basename "$originalFilePath")\" with title \"Conversion Success\""
    else
        osascript -e "display notification \"Failed: $(basename "$originalFilePath")\" with title \"Conversion Failure\""
    fi
done


You could also wrap this script in an Automator Application instead of a Service. Then you can drag and drop multiple files onto the app icon, and it will process them all.
 
Back
Top Bottom