Skip to content

Instantly share code, notes, and snippets.

@neosarchizo
Created March 5, 2017 14:22
Show Gist options
  • Save neosarchizo/1a8098371fc731c97c09ad76389df01f to your computer and use it in GitHub Desktop.
Save neosarchizo/1a8098371fc731c97c09ad76389df01f to your computer and use it in GitHub Desktop.
Save as pdf by applescript
set AppleScript's text item delimiters to ".pdf"
repeat while true
tell application "System Events"
tell process "Your Application"
if exists window "Print" then
tell window "Print"
if not (exists sheet 1) then
click menu button "PDF"
repeat until exists menu item "Save as PDF…" of menu 1 of menu button "PDF"
end repeat
click menu item "Save as PDF…" of menu 1 of menu button "PDF"
repeat until exists sheet 1
end repeat
tell sheet 1
set maxFileNumber to 0
tell application "Finder"
set fileList to name of every file of folder "Macintosh HD:Users:neosarchizo:Downloads:"
repeat with currentFile in fileList
if ".pdf" is in currentFile then
set currentFileNumber to (text item 1 of currentFile) as integer
if currentFileNumber > maxFileNumber then
set maxFileNumber to currentFileNumber
end if
end if
end repeat
set maxFileNumber to maxFileNumber + 1
end tell
keystroke maxFileNumber
click button "Save"
end tell
end if
end tell
end if
end tell
end tell
end repeat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment