Skip to content

Instantly share code, notes, and snippets.

@cawka
Created September 3, 2019 02:38
Show Gist options
  • Save cawka/7b4cb46dad382efeef229c8bd93a3f4c to your computer and use it in GitHub Desktop.
Save cawka/7b4cb46dad382efeef229c8bd93a3f4c to your computer and use it in GitHub Desktop.
#!/usr/bin/osascript
on run argv
if not (count argv) = 2
return "Usage:\n docx-to-pdf <input file> <output file>"
end if
set pwd to do shell script "pwd"
set _input to item 1 of argv as text
set _output to item 2 of argv as text
if not _input starts with "/"
set _input to pwd & "/" & _input
end if
if not _output starts with "/"
set _output to pwd & "/" & _output
end if
try
set _input to (get POSIX file _input as alias)
on error errStr number errorNumber
return "ERROR: File [" & _input & "] does not exists or cannot be opened"
end try
set _output to (get POSIX file _output as string)
tell application "Microsoft Word"
set default file path file path type documents path path _input
open _input
set theActiveDoc to the active document
save as theActiveDoc file format format PDF file name _output
close theActiveDoc
end tell
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment