This is a private note that has been shared.
# The full file path passed from Hazel
set file "$argv[1]"
# Generate the output file name (replace the extension with .mp4)
set output_file (string replace -r '\.[^.]*$' '.mp4' "$file")
# Get the directory path of the original file
set dir (dirname "$file")
# Set the error folder path (create error_files folder in the same directory)
set error_folder "$dir/error_files"
# Create the error folder if it doesn't exist
if not test -d "$error_folder"
mkdir "$error_folder"
end
# Convert the file using FFmpeg (to mpg/aac/HEVC format)
ffmpeg -i "$file" -c:v libx265 -c:a aac "$output_file"
# Check if the conversion was successful
if test $status -eq 0
# If successful, delete the original file
rm "$file"
else
# If conversion failed, copy the file to the error folder
cp "$file" "$error_folder"
# Check if copying was successful before deleting the original file
if test $status -eq 0
rm "$file"
end
end