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

  • Choose Run AppleScript (under Utilities category or use the Search input field).
  • Paste the following AppleScript.
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
            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 then
                    set 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.


Linux setup

As I said in the previous post (Setup), I have chosen a desktop distribution in order to save some time editing files but some configuration is still needed.

Set Static IP address

It’s nice but also bad that each time that you restart a computer you get a different IP address, specially if this is a server (or provide some sort of service) and then you need to configure the clients.

Since our Linux box is going to be in a separate machine, lets set a static IP address in order to easily find it.

  1. On you Mac go to /Library/Application Support/VMware Fusion/vmnet8and edit dhcp.conf adding at the end of the file the following lines:
    host couchdb64 {
        hardware ethernet 00:50:56:28:99:48

    You get hardware ethernet from the settings of the Virtual Machine > Network > Advanced Options and then click on Generate.

  2. Go to System Setting > Network > Wired > Options >  IPv4 Settings and Edit Addresses

Install CouchDB

We are going to do this from Ubuntu repositories (even that you might opt to go with a version downloaded from Apache CouchDB site but then you have to compile it by yourself following their instructions). This is pretty simple:

couchdb:~$ sudo apt-get install couchdb
Reading package lists... Done
Building dependency tree 
Reading state information... Done
The following extra packages will be installed:
 couchdb-bin erlang-base erlang-crypto erlang-inets erlang-mnesia
 erlang-public-key erlang-runtime-tools erlang-ssl erlang-syntax-tools
* Starting database server couchdb [ OK ] 
Setting up erlang-syntax-tools (1:14.b.4-dfsg-1ubuntu1) ...
Setting up libsctp1 (1.0.11+dfsg-2) ...
Setting up lksctp-tools (1.0.11+dfsg-2) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place

Change CouchDB listening IP address/port

Now, the problem is that CouchDB is only listening at localhost ( and we want to access from other machines so we need to change CouchDB IP/port.

Edit /etc/couchdb/local.ini file and look for the label [httpd] and there is bind_address  property that you should edit and change to (your static IP address).

;port = 5984
bind_address =

You might also be willing to set bind_address to for making CouchDB list to all network interfaces.

Restart CouchDB server:

couchdb:/etc/couchdb$ sudo service couchdb restart 
 * Restarting database server couchdb [ OK ] 

Open your web browser in the Mac and try to access and you should see {“couchdb”:”Welcome”,”version”:”1.0.1″} as response. If you open the URL then you get CouchDB futon.


I´m going to be using for this project an Apple MacBook Pro but actually most of the software used is available also for Linux and Windows platforms. So hopefully you are not going to have problems replicating the setup.

List of elements of the setup:

  • Application server: Apache Tomcat 7.0 on the MacBook Pro. Apache Tomcat is downloaded as binary from Apache site and just uncompressed in my project folder.
  • CouchDB Server: on an Ubuntu Desktop 12.04 LTS (64 bits) virtual machine running in the MacBook Pro using VmWare Fusion (I love VmWare products since many years and likely that VirtualBox, Parallels,… are as good but I’ve started with VmWare and they run well for what I need and typically I can afford their prices).
    Yes! One question about the Linux distribution that I’ve chosen… since this project is likely to keep me bussy for some time, I got the latest. And about “Desktop” and not “Server” because I don’t want to have to do some manual configuration as switching keyboard layout, configure IP address… and whenever I want to do some (serious) performance testing I will try to find another machine and then I will install server. Nevertheless, I do a lot of manual (console) operations specially for those that I use to do quite ofter (start services, install packages,…).
  • CouchDB is directly installed from Ubuntu repositories (sudo apt-get install couchdb).
  • Ubuntu machine uses NAT and fixed IP address just to make sure that each time I reboot it I can easily find it.
  • IDE: IntelliJ IDEA (sorry! I’m not an Eclipse follower just because I’ve started using Idea years ago and I’m not about to switch as far as I don’t have to and Idea offers me what I need).

This is basically about it… Hopefully pretty simple.