Last active
October 22, 2021 18:09
-
-
Save m-graf/ab76972ebba4170dbefc794d1afe95f9 to your computer and use it in GitHub Desktop.
AppleScript to convert + compress HEIC images to JPG. Can be compiled into an Application with Apple Script.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Converts all .HEIC files in directory ($1) to .jpg | |
# Outputs converted images to $2 | |
if ! command -v /usr/local/bin/magick &> /dev/null | |
then | |
echo "magick could not be found, you need to install it." | |
exit | |
fi | |
for f in $1*.HEIC | |
do | |
DIR_NAME=`dirname "$f"` | |
BASE_NAME=`basename "$f"` | |
/usr/local/bin/magick convert "$f" \ | |
-sampling-factor 4:2:0 \ | |
-strip \ | |
-quality 65% \ | |
-interlace JPEG \ | |
-gaussian-blur 0.05 \ | |
"$DIR_NAME/$2/$BASE_NAME.jpg" | |
done | |
echo "Done." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
The zero_pad function taken from: | |
http://www.nineboxes.net/2009/10/an-applescript-function-to-zero-pad-integers/ | |
*) | |
on zero_pad(value, string_length) | |
set string_zeroes to "" | |
set digits_to_pad to string_length - (length of (value as string)) | |
if digits_to_pad > 0 then | |
repeat digits_to_pad times | |
set string_zeroes to string_zeroes & "0" as string | |
end repeat | |
end if | |
set padded_value to string_zeroes & value as string | |
return padded_value | |
end zero_pad | |
on run | |
set now to (current date) | |
set result to (year of now as integer) as string | |
set result to result & "- " | |
set result to result & zero_pad(month of now as integer, 2) | |
set result to result & "-" | |
set result to result & zero_pad(day of now as integer, 2) | |
set result to result & "@" | |
set result to result & zero_pad(hours of now as integer, 2) | |
set result to result & "-" | |
set result to result & zero_pad(minutes of now as integer, 2) | |
set result to result & "-" | |
set result to result & zero_pad(seconds of now as integer, 2) | |
return result | |
end run |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set script_name to ".convert_heic_to.sh" | |
tell application "Finder" | |
set current_path to container of (path to me) as alias | |
end tell | |
set postix_path to POSIX path of current_path | |
set current_datetime to run script postix_path & ".current_datetime.scpt" | |
tell application "Finder" | |
set current_path to container of (path to me) as alias | |
make new folder at current_path with properties {name:current_datetime} | |
end tell | |
set scriptcommand to postix_path & script_name & " " & postix_path & " " & current_datetime | |
do shell script scriptcommand | |
display dialog "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment