ColorSync Filter Script

I’m working on a script that will apply ColorSync filters to PDF files. I have included below my bare-bones working script, which uses ASObjC code written by Shane. This works well and is what I will probably use, but I wanted to see if there are any other alternatives that should be considered.

Two alternatives that will do the job are Automator and the Preview app, but they are not options in my case. Also, there used to be a quartzfilter utility that could be used but it’s not included in Catalina. Finally, I thought perhaps Image Events could be used but that does not appear to be the case.

My questions:

  • Is there any other AppleScript method that will apply ColorSync filters to PDF files?

  • Shane wrote the ASObjC code 6 years ago and I wondered if Shane or other forum member would recommend any changes?

I obtained Shane’s code from post 6 in:

My current script:

use framework "Foundation"
use framework "Quartz"
use scripting additions

set filterFolder to (POSIX file "/System/Library/Filters/") as alias

tell application "Finder" to set sourceFile to selection as alias
set sourceFile to POSIX path of sourceFile
set filterFile to POSIX path of (choose file "Select a Filter" default location filterFolder)

set text item delimiters to {".pdf"}
set destinationFile to (text 1 thru text item -2 of sourceFile) & " - filter applied.pdf"
set text item delimiters to {""}

applyFilter(sourceFile, destinationFile, filterFile)

on applyFilter(sourceFile, destinationFile, filterFile)
	set filterPath to current application's NSString's stringWithString:filterFile
	set filterURL to current application's NSURL's fileURLWithPath:filterPath
	set filterFile to current application's QuartzFilter's quartzFilterWithURL:filterURL
	set pdfURL to current application's NSURL's fileURLWithPath:sourceFile
	set thePDFDoc to current application's PDFDocument's alloc()'s initWithURL:pdfURL
	set theOptions to {QuartzFilter:filterFile}
	thePDFDoc's writeToFile:destinationFile withOptions:theOptions
end applyFilter


Nothing’s changed with the filters, as far as I know. There is a dedicated filter selection panel, but I don’t know that it would be worth the added complication.

Thanks Shane and Fredrik71. My existing approach with Shane’s ASObjC code works well and I’ll use that. I’ve posted a copy of my finished script in the Code Exchange forum.