Skip to content

Instantly share code, notes, and snippets.

@lcuevastodoit
Last active January 20, 2023 17:32
Show Gist options
  • Save lcuevastodoit/2a8c5d20864a3a8211eaaacb5cf4c495 to your computer and use it in GitHub Desktop.
Save lcuevastodoit/2a8c5d20864a3a8211eaaacb5cf4c495 to your computer and use it in GitHub Desktop.
mov-to-gif converter on mac context menu

To create a context menu action in the Mac Finder to convert a .mov video using ffmpeg via the command line, you can use the Automator app. Here are the steps: You need to install ffmpeg and gifsicle

brew install ffmpeg
brew install gifsicle
  • In the mac spotlight open Automator.app and create a new "Quick Action"
  • In the search bar, look for "Run Shell Script" and drag it to the right pane.
  • In the "Service receives selected" dropdown, select "files or folders"
  • In the "Pass input" dropdown, select "as arguments"
  • Copy paste this script in the script section
  • Save the service with a desired name
original_file_path="$1"
original_file_directory=$(dirname "$original_file_path")


/usr/local/bin/ffmpeg -y -i "$original_file_path" -pix_fmt rgb8 -r 5 "$original_file_directory/$(basename "$original_file_path" .mov).gif"

if /usr/local/bin/gifsicle -O3 "$original_file_directory/$(basename "$original_file_path" .mov).gif" -o "$original_file_directory/$(basename "$original_file_path" .mov).gif"; then osascript -e 'display notification "File: '"$(basename "$output_file")"'  has been converted optimized" with title "Conversion"'
else
   if /usr/local/bin/gifsicle --unoptimize "$original_file_directory/$(basename "$original_file_path" .mov).gif" -o "$original_file_directory/$(basename "$original_file_path" .mov).gif"; then osascript -e 'display notification "File: '"$(basename "$output_file")"'  has been converted unoptimized" with title "Conversion"'
   else
     osascript -e 'display notification "File: '"$(basename "$output_file")"'  convertion ERROR retry later" with title "Conversion"'
   fi
fi

    
  • Right click on a .mov file in Finder, you should see the new service in the context menu.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment