15 May

Using Automator to convert Pages to PDF

Recently we were asked how to use Automator to convert Apple Pages documents into PDFs. In the spirit of sharing the knowledge, here’s how we did it.

It’d be great to make an app which we could drop our Pages files on and have them made into PDFs. The obvious way to make such an app is with Automator. Unfortunately, Pages doesn’t ship with Automator actions (although there are some funky third party options)

Luckily, Pages is AppleScriptable so we can make our own action. Let’s look at how to do that.

First, launch Automator (you’ll find it in your Mac’s Applications folder). Select “Application”.

Screen Shot 2016-05-12 at 13.19.38

Next, drag a “Run AppleScript” workflow into your workflow so you have something that looks like this:

Screen Shot 2016-05-12 at 13.20.06

Replace all the purple text in the action with the following AppleScript:

on run {input, parameters}

repeat with theFile in input
tell application "Finder"
set theFilesFolder to (folder of theFile) as text
end tell

tell application "Pages"
set theDoc to open theFile

set theDocName to name of theDoc
set theName to (characters 1 thru -7 of theDocName) as text
export theDoc as PDF to file ((theFilesFolder & theName & ".pdf") as text)

close theDoc

end tell
end repeat
return input
end run

Save the workflow and you should now have an app that you can drop Pages documents on.

Note that it’s up to you to make sure that the documents you drop actually are Pages documents – the script doesn’t check and may error if you drop the wrong type of documents.

On a related note, if you’d rather dodge the AppleScripting all together then you could try out our handy Pages Automator Actions.

While we have your attention… why not check out our macOS apps?

Barcode Basics – macOS barcode generator (including Automator support)
Ai Actions – Automator action pack for Adobe Illustrator
Pages Automator Actions – Automator action pack for Pages

09 May

Backing up a folder on macOS with rsync

Terminal

Quite often we’re asked how to keep a backup folder in sync with a work in progress folder. There are many possible solutions apps and third party solutions out there, but its quite easy to set up a rough, homespun backup solution. All you need is a little command line wizardry using something called rsync.

Syncing with rsync

First, lets imagine we have two folders on our desktop. One is called WIP, which contains all my work in progress. The other is called Backup which is where I’d like to keep a backup of all my WIP.

Open up a Terminal window (you’ll find Terminal in /Applications/Utilities) and type:

rsync -av --delete

Don’t hit return yet! Next, drag the WIP folder onto your Terminal to get the path to your folder. Add a slash to the end of it. You should have something like this:

rsync -av --delete /Users/YourUserName/Desktop/WIP/

Don’t hit return yet! Of course, the path will be different on your Mac – don’t worry about it. Next, drag the Backup folder onto the Terminal. You should now have something like this:

rsync -av --delete /Users/YourUserName/Desktop/WIP/ /Users/YourUserName/Desktop/Backup

Now you can hit return! You should find that the contents of WIP are copied to Backup. If you run the command a second time, nothing will happen. This is the beauty of rsync. It’s smart enough to only copy files from WIP if an identical copy doesn’t already exist in Backup. Our “–delete” option means that anything in in Backup that’s NOT in WIP gets deleted.

Of course, your backup folder can be anywhere – on an external drive or even on a remote server.

Scheduling

There are a number of ways to make this rsync command run a schedule. You could run it via a scheduled Automator action, via cron using something like Cronnix, or (my favourite) using a Launch Agent.

Have fun with your new backup command!

While we have your attention… why not check out our macOS apps?

Barcode Basics – macOS barcode generator (including Automator support)
Ai Actions – Automator action pack for Adobe Illustrator
Pages Automator Actions – Automator action pack for Pages

09 May

How to split PDF into PNG files in OS X

One pdf to multiple png files

We were asked recently how to split a PDF file into PNG files on Mac OS X. That’s to say, if the PDF has five pages then you’d want five PNG files produced, one for each page. Here are some options:

Adobe Acrobat
If you have Adobe Acrobat (not to be confused with the free Acrobat Reader) then you an simply open the PDF and select File>Save As and select “PNG”. However, Acrobat is expensive for what it is and there are some free alternatives such as…

PROs: Very easy to do
CONs: Acrobat Pro is expensive and probably not worth the price if this is all you’ll ever use it for.

Third party website
Probably the easiest way is to use a web site such as pdf2png.com. Whilst I’m sure they’re a reputable site and we’ve used them successfully in the past, its always worth thinking twice before uploading anything that may be confidential to a third party site.

PROs: Also very easy
CONs: Can be slow if you need to upload a big pdf. Think about security.

ImageMagick
If you’re comfortable on the command line then you can use ImageMagick to do the heavy lifting. If you don’t have it installed already then we recommend using the installer from Cactus Labs.

Once you have ImageMagick installed, you can fire up the Terminal and use a command like:

convert ~/Desktop/myfile.pdf ~/Desktop/myfile.png

…and ImageMagick should do the rest, including sequentially naming the files. Don’t forget to change the paths to the documents to your own!

PROs: Completely free. Also ImageMagick has lots of other uses if you work with graphics. It’s worth having in your arsenal! For extra credit, you can even get ImageMagick working through Apple’s Automator to build your own custom workflow.
CONs: You need to be reasonably comfortable with using the Terminal.

There are plenty of other ways, but these are the ones that work best in our experience. Let us know if you’ve found any better ways!

While we have your attention… why not check out our macOS apps?

Barcode Basics – macOS barcode generator (including Automator support)
Ai Actions – Automator action pack for Adobe Illustrator
Pages Automator Actions – Automator action pack for Pages

03 May

Automating HTML to PDF conversion on OS X

Ever wondered how to convert a big batch of html files into PDFs?

Well, you *could* open each html file in the web browser of your choice and save/print it as a PDF. However, that’s going to take a long time for a big batch. One fun way you can do it in macOS is by creating an Automator service to do the donkey work for you. Let’s take a look at how to do that.

First, launch Automator (you’ll find it in your Mac’s Applications folder) and create a Service document (NB. Click any of the screen shots here to enlarge them).

Create Automator Service

Next, set the services input options as shown below.

Screen Shot 2016-05-03 at 14.09.55

Next drag in a Run Shell Script action. Make sure you set it’s “Pass input” option to “as arguments” – that’s important! This lets us pass the files we select as an input to the shell script.

Screen Shot 2016-05-03 at 14.10.33

Change it’s contents to:

for theFileToProcess in "$@"
do
cupsfilter "$theFileToProcess" > "${theFileToProcess%.*}.pdf"
done

And save it as “HTML 2 PDF”, or whatever makes sense to you. Now it should look like this:

Run Shell Script options

Now, if you select a one (or more!) HTML files in in Finder whilst holding your control key down, you should be able to find the service you just created under “Services”. as shown below. Select it and you’ll run the shell script on all the files you selected!

Screen Shot 2016-05-03 at 14.13.29

Note that this will work best on fairly simple html – if you have heaps of JavaScript, movies etc in your html then the PDFs may not be great. However, its a handy quick way of taking some of the pain out of converting html to pdf.

While we have your attention… why not check out our macOS apps?

Barcode Basics – macOS barcode generator (including Automator support)
Ai Actions – Automator action pack for Adobe Illustrator
Pages Automator Actions – Automator action pack for Pages