Convert Word files (DOC/DOCX) to PDF in OSX

Convert Word files (DOC/DOCX) to PDF in OSX

If you need to convert a file from Word to PDF you probably select print to PDF from Word but when you need to convert multiple files you need to script it.

AppleScript for converting Word into PDF

  • Open Automator.
  • Select Service and click Choose.

  • In the top of the screen choose Service receives selected: files or folders in Finder.app.

  • Choose Run AppleScript (under Utilities category or use the Search input field).

  • Paste the following AppleScript.
1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

property theList : {"doc", "docx"}

on run {input, parameters}

set output to {}

tell application "Microsoft Word" to set theOldDefaultPath to get default file path file path type documents path

repeat with x in input

try

set theDoc to contents of x

tell application "Finder"

set theFilePath to container of theDoc as text

set ext to name extension of theDoc

if ext is in theList thenset theName to name of theDoc

copy length of theName to l

copy length of ext to exl

set n to l - exl - 1

copy characters 1 through n of theName as string to theFilename

set theFilename to theFilename & ".pdf"

tell application "Microsoft Word"

set default file path file path type documents path path theFilePath

open theDoc

set theActiveDoc to the active document

save as theActiveDoc file format format PDF file name theFilename

copy (POSIX path of (theFilePath & theFilename as string)) to end of output

close theActiveDoc

end tell

end if

end tell

end try

end repeat

tell application "Microsoft Word" to set default file path file path type documents path path theOldDefaultPath

return output

end run

  • Save it as Word2PDF (or any other name)

  • For running it just right click your mouse on top of a file or folder and you will see the new service in the context menu.

Реклама

Добавить комментарий

Заполните поля или щелкните по значку, чтобы оставить свой комментарий:

Логотип WordPress.com

Для комментария используется ваша учётная запись WordPress.com. Выход / Изменить )

Фотография Twitter

Для комментария используется ваша учётная запись Twitter. Выход / Изменить )

Фотография Facebook

Для комментария используется ваша учётная запись Facebook. Выход / Изменить )

Google+ photo

Для комментария используется ваша учётная запись Google+. Выход / Изменить )

Connecting to %s