Skip to content

Instantly share code, notes, and snippets.

@rpapallas
Created June 30, 2019 17:37
Show Gist options
  • Save rpapallas/76f7940e394b0b0f1772b226d05ae39d to your computer and use it in GitHub Desktop.
Save rpapallas/76f7940e394b0b0f1772b226d05ae39d to your computer and use it in GitHub Desktop.
A simple AppleScript to automatically (lossless) compress a PDF using PDFExpert Compress Feature.
# Copyright (C) 2019 Rafael Papallas
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set filePath to "~/Desktop/some.pdf"
do shell script "open " & quoted form of filePath
delay 1.0
activate application "PDF Expert"
delay 1
tell application "System Events"
tell process "PDF Expert"
click menu item "Reduce File Size..." of menu 1 of menu bar item "File" of menu bar 1
delay 1
tell pop up button 1 of sheet 1 of window 1
click
tell menu 1
click menu item "Lossless"
end tell
end tell
-- Wait until the compression is done.
repeat until button "Save" of sheet 1 of window 1 is enabled
end repeat
click button "Save" of sheet 1 of window 1
key code 36
-- Close the compressed file
click menu item "Close Tab" of menu 1 of menu bar item "File" of menu bar 1
end tell
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment