Page 1 of 1

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

PostPosted: Tue Apr 18, 2023 8:20 pm
by MacRail
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.

Re: Convert u/l iPhone photos from HEIC to jpg/png automatic

PostPosted: Thu Jul 27, 2023 5:42 pm
by chrisjones
Wow! It looks very easy. Great work

Re: Convert u/l iPhone photos from HEIC to jpg/png automatic

PostPosted: Tue Aug 15, 2023 5:31 pm
by kevnm67
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"