Convert u/l iPhone photos from HEIC to jpg/png automatically

From your noodle to other noodles. Talk about ways to get the most from Hazel. Even exchange recipes for the cool rules you've thought up. DO NOT POST YOUR QUESTIONS HERE.

Moderators: Mr_Noodle, Moderators

Perhaps I'm brute forcing something that has an easier solution, but I don't like my uploaded (airdropped) iPhone photos to be in HEIC format on my Mac. So I have a Downloads folder rule in Hazel that runs the following three scripts for every uploaded file:

/opt/homebrew/bin/convert $1 $1.png

VAR=$1
/opt/homebrew/bin/rename s/HEIC\.// $VAR.png

/bin/rm $1

[I guess could all be one script - can't remember why I split it into three separate scripts.]

Now to make all that work, you have to previously have installed 'brew' and then install 'imagemagik'. But this works like a charm and is very reliable.
MacRail
 
Posts: 1
Joined: Tue Apr 18, 2023 8:11 pm

Wow! It looks very easy. Great work
chrisjones
 
Posts: 2
Joined: Wed Jul 19, 2023 10:54 pm

Thanks for the useful script! I updated my version of it if interested.

Code: Select all
#!/usr/bin/env bash

# Exit script if you try to use an uninitialized variable
set -o nounset

# Use the error status of the first failure, rather than that of the last item in a pipeline
set -o pipefail

##########
# Script #
##########

brew_bin="/opt/homebrew/bin"

install_if_needed() {
   # ensure brew formula installed.  Else, install it.
   if ! [ -x "$(command -v "$1")" ]; then
      echo "Installing $1..."
      brew install "$1"
   fi
}

convert() {
   install_if_needed rename
   
   echo "converting $1 to png"
   
   "$brew_bin"/convert "$1" "$1".png
   
   # Rename HEIC filename (e.g. remove .HEIC.)
   "$brew_bin"/rename s/HEIC\.// "$1".png
}

########
# Main #
########

convert "$1"
kevnm67
 
Posts: 3
Joined: Sat Nov 29, 2014 11:33 pm


Return to Tips & Tricks - DO NOT POST QUESTIONS