Skip to content

Instantly share code, notes, and snippets.

@codingChewie
Last active March 24, 2021 16:38
Show Gist options
  • Save codingChewie/bc8e1e822820c237b40d7afba13c99a0 to your computer and use it in GitHub Desktop.
Save codingChewie/bc8e1e822820c237b40d7afba13c99a0 to your computer and use it in GitHub Desktop.
AppleScript that helps identify a color's profile with Macs built in SIPs
(*
Date: 16-12-21
Developer: codingChewie
Purpose: Color Labels images to help identify the color profile.
Version: 1.1
Name: image-profile.scpt
Blog: https://programmingmonkeys.com/
*)
property dialogTitle : "Image Profiler"
property jpgGroup : {"jpg", "jpeg", "JPG", "JPEG"}
property pngGroup : {"png", "PNG"}
property bmpGroup : {"bmp", "BMP"}
property tifGroup : {"tif", "TIF", "tiff", "TIFF"}
property imgCluster : jpgGroup & pngGroup & bmpGroup & tifGroup
on imageProfile(imgItems)
repeat with imgItem in imgItems
tell application "Finder"
set label index of imgItem to 0
end tell
set imgItemPosix to POSIX path of imgItem
set imgColorProfile to do shell script "sips -g space " & " " & imgItemPosix & " " & "| tail -n1 | cut -d' ' -f4"
## display dialog imgColorProfile as string
if imgColorProfile is equal to "CMYK" then
tell application "Finder"
set label index of imgItem to 4
end tell
else if imgColorProfile is equal to "RGB" then
tell application "Finder"
set label index of imgItem to 6
end tell
else if imgColorProfile is equal to "Gray" then
tell application "Finder"
set label index of imgItem to 7
end tell
else if imgColorProfile does not contain {"RGB", "CMYK", "Gray"} then
tell application "Finder"
set label index of imgItem to 5
end tell
end if
end repeat
end imageProfile
on run
try
set theLocation to (choose folder with prompt "Please select a directory.")
tell application "System Events"
if kind of theLocation is "Folder" then
set folderItems to items of theLocation whose visible is true
set totalCount to count of folderItems
if totalCount = 0 then
set workingFolder to do shell script "open " & (POSIX path of theLocation)
tell application "Finder"
set the bounds of the front Finder window to {0, 10, 750, 420}
say "the folder is empty"
end tell
else
tell application "Finder"
set imgItems to (files of folder theLocation where name extension is in imgCluster) as alias list
my imageProfile(imgItems)
end tell
end if
end if
end tell
display notification "Script has completed" with title dialogTitle
on error error_message number error_number
if error_number is equal to -128 then
display notification "Script was cancelled" with title dialogTitle
else
display dialog error_message with title dialogTitle
end if
end try
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment