AppleScript error opening pdf in preview
macOS Sierra Version 10.12.6.
Hello, I'm trying to reduce the size of multiple pdfs, however the script below prompts error: line ending expected, but class name found. The script also highlights line 19's word document.
-- Compress PDFs using Preview's Quartz Filters
set quartzFilter to "Reduce File Size" -- Replace with your Quartz filter name
set outputFolder to (choose folder with prompt "Select the folder to save compressed PDFs:")
tell application "Finder"
set pdfFiles to (choose file of type "PDF" with prompt "Select PDF files to compress:" with multiple selections allowed)
end tell
repeat with pdfFile in pdfFiles
set inputFilePath to (pdfFile as text)
set outputFilePath to ((outputFolder as text) & (name of (info for pdfFile)))
tell application "Preview"
open pdfFile
delay 1 -- Allow time for Preview to load the file
try
export document 1 to file outputFilePath as PDF using Quartz filter quartzFilter
close document 1
on error errMsg
display dialog "Error processing file: " & (name of (info for pdfFile)) & ". Error: " & errMsg
end try
end tell
end repeat
display dialog "Compression complete!" buttons {"OK"} default button "OK"
Mac mini, macOS 10.13