I’ve been using the PDF Squeezer app (also available through Setapp) as I find it reduces the file size better than other methods, particularly for PDFs with giant embedded photos. I’ve automated it using a Smart Rule but before I let it go crazy on my precious records, would someone take a look and let me know if I’ve screwed it up somehow or, even better, if there’s a superior way of achieving this same result please?
It seems to work but this is unfamiliar territory and the people on this forum are always so kind and helpful. Thank you in advance.
on performSmartRule(theRecords)
tell application id "DNtp"
repeat with theRecord in theRecords
set recPath to (path of theRecord)
set qRecPath to quoted form of recPath
do shell script "$HOME/bin/compress-pdf.sh " & qRecPath
end repeat
end tell
end performSmartRule
compress-pdf.sh
NB pdfs is the command-line version of PDF Squeezer
#!/bin/zsh
# compress-pdf.sh
# Compress PDF using PDF Squeezer
# Check if the pdfs command is available
if ! command -v /usr/local/bin/pdfs &> /dev/null ; then
echo "pdfs command not found. Please install PDF Squeezer package."
exit 1
fi
# Check if a file is provided as an argument
if [[ $# -eq 0 ]]; then
echo "Usage: $0 <PDF_FILE>"
exit 1
fi
# Get the input file path
input="$1"
# Check if the file exists
if [[ ! -f "$input" ]]; then
echo "File not found: $input"
exit 1
fi
/usr/local/bin/pdfs "$input" --profile "$HOME/appconfig/PDF Squeezer/Medium.pdfscp" --replace
It is better to be more specific in searches, smart groups, and smart rules, so I suggest adding a criterion: Kind is PDF/PS. And there’s no size threshhold to filter down to PDFs that really need squeezing. Do you really need to do this often enough to create a smart rule for it?
The echo’s wont go anywhere but it’s non-fatal.
"$HOME/bin/compress-pdf.sh "
Is this installed in this location by PDF Squeezer?
Thank you as always Jim. These are terrific suggestions. I’ve added the PDF/PS criterion. The shell script is mine, but PDF Squeezer does install pdfs to /usr/local/bin/ by default. Is there a way to direct the echos back into DT?
I wouldn’t say I compress files frequently but some PDF web clips are unnecessarily large. For example, this one saves as 36mb but compresses down to 3.5mb. More significantly, I mostly work on a MacBook but have a Mac mini always running in the background with DT. By adding a tag on the MacBook, it’ll get compressed on the Mini in the background once I change the triggers. (And I don’t have to run PDF Squeezer locally - it’s a Rosetta app.)
FYI, I use PDF Squeezer all the time on most the PDFs that I capture. It’s quick and fast. When I first started with it I like you thought I would create a Smart Rule to use it automatically. I did not pursue as I thought I needed the command line interface option, but I’ve been unable to get it going and the developer hasn’t answered my questions–my only quibble with the product.
So in the meantime I learned how easy it is to select, say all the PDFs still in the Inbox, then drag/drop them into PDF Squeezer. PDF Squeezer set by default to do “Strong Compression”. But for some documents that’s too much. PDF Squeezer shows the original and “squeezed” version and for those PDFs that become “fuzzy”, I change to “Medium Compression” which normally corrects the fuzziness even on images. Once happy with the set of squeezed PDFs, I select all and save back into DEVONthink. Sometimes the reduction is orders of magnitude without significant loss in readability.
So, despite the command line option and lack of support, it’s a good product.
Thanks! Like you, I found the Medium profile to work the best. You can export the profile from PDF Squeezer → Settings. I saved it as $HOME/appconfig/PDF Squeezer/Medium.pdfscp.
Both parameters after the input filename are optional. --profile to make it use the Medium profile, --replace so it overwrites the input file with the compressed file. The latter is the equivalent of doing an Open With… PDF Squeezer in DT, then once PDF Squeezer has compressed the file, saving it.
If you’d still like to pursue a command-line automation then what is above will work and works even better and safer with Jim’s suggestions. My main stumbling block was not understanding how to get the DT record’s full path including filename (and then ensuring it was quoted).
As I’m sure you already know, you have to install the command-line pdfs from the Settings first. (I also used these automation tools to create a simple macOS Shortcut attached to a Finder Quick Action.)
Under recent versions of macOS, you may also need to give the Terminal access to the DT directory in macOS System Settings → Privacy & Security → Files and Folders or Full Disk Access.
Actually, I use “Strong” probably 98% of the time for that orders of magnitude squeeze I mentioned. Most of my stuff is text. “Medium” only by exception and then only for those PDFs that have images that I find important enough to keep not-fuzzy. If i make the wrong decision and Strong squeeze something that later I can’t read, I can always go back to the original (if still available, which is likely).
My problem with the automation setup in PDF Squeezer is the “grant access” button which reports the error:
“The open file operation failed. The open file operation failed to connect to the open and save panel service”.
From that I conclude it “failed”. What to fix or repair is a mystery. Not really important to me anymore as I have the process as described above as without AI making the decisions on compression levels, I use my aging and hopefully-not-artificial brain/eyes.
I also use the PDF Squezer. However, I do not use a shell script for the compression but the PDF Squezer Action in a workflow. I have realised that the action runs more stable than a shell script. If you are interested, I can post the workflow here, maybe it will help someone.
It would be more helpful to post code as such – copy/pasting a screenshot is not useful.
Include code in three backticks like so
``` code goes here
```
Many thanks for the suggestion. If you can explain to me how I can make the code part of the PDF Squeezer (in the centre) visible so that I can copy it too. Then I’ll be happy to do it! I didn’t find the variant of working with code AND screenshot useful.
Also, you should use selected records instead of selection. And copying the selection to a new list should not be necessary – just return selected records if anything is selected.
ok, here we go.
I was not able to get it working with removing the “copying” part. Perhaps I did not understand what you mean.
Start of the workflow
on run {}
tell application id "DNtp"
try
activate
set fileList to {}
if selected records ≠ {} then
repeat with thisRecord in (selected records as list)
copy (path of thisRecord) to end of fileList
end repeat
end if
return fileList
end try
end tell
end run
Picture for the middle, see some posts below
end of the workflow
tell application id "DNtp"
set theSelection to selected records
repeat with theRecord in theSelection
deconsolidate record theRecord
synchronize record theRecord
end repeat
end tell