Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ign

macrumors member
Original poster
Mar 16, 2004
37
1
Firenze
Hello,

I need to convert a bunch of PostScript files to pdf.
With OSX one can open the postscript file and save it in pdf,
but I can't do it one by one, it'd take for ever.
Is there a command in terminal that does it for a batch of files ??

thank you!
 

costabunny

macrumors 68020
May 15, 2008
2,466
71
Weymouth, UK
Ive used CS3 batch for BMP to Tiff - I don't know but I'd take a guess that it will do postscript to PDF also ? (maybe someone knows)
 

whooleytoo

macrumors 604
Aug 2, 2002
6,607
716
Cork, Ireland.
In /Library/Scripts/Printing Scripts/ you'll find the Convert to PDF applescript, you should be able to modify that to do what you want. It ultimately uses cupsfilter, so if you want to write a shell script rather than Applescript you could look at the man documentation for that.
 

jaw04005

macrumors 601
Aug 19, 2003
4,513
402
AR
I thought PostScript was a printer language, not a file type like PDF. Oh well, you learn something everyday.
 

lloyddean

macrumors 65816
May 10, 2009
1,047
19
Des Moines, WA
No answer from anyone knowledgeable in shell scripting, that includes me, but I'll try anyway.

Save the following to a file called 'ps2pdf' somewhere in your path followed by a 'sudo chmod 777 ps2pdf' on the file to give it permission for anyone to read, write and execute it.

Invoke it with the list of files you wish to convert. PDF files will be created with the same name as the source files minus the .ps but appended with .pdf.
Example

ps2pdf *.ps

Code:
#!/bin/bash
#
# sudo chmod 777 ps2pdf

for f in *.ps
do
	pstopdf "$f"
done
 

chown33

Moderator
Staff member
Aug 9, 2009
10,750
8,422
A sea of green
Code:
for f in *.ps

That line should be:

Code:
for f in "$@"

You don't have to make it a separate shell script, though. The OP could just copy and paste these lines into a Terminal window (assuming his shell is bash).

Code:
for f in *.ps
do
	pstopdf "$f"
done

This assumes the ps files all end in ".ps", and they are all in the current directory. To improve the script, though, we'd need the OP to tell us more about where the ps files are located, e.g. whether they're in nested sub-dirs, on a remote server, etc.
 

lloyddean

macrumors 65816
May 10, 2009
1,047
19
Des Moines, WA
That line should be:

Code:
for f in "$@"

You don't have to make it a separate shell script, though. The OP could just copy and paste these lines into a Terminal window (assuming his shell is bash).

Code:
for f in *.ps
do
	pstopdf "$f"
done

This assumes the ps files all end in ".ps", and they are all in the current directory. To improve the script, though, we'd need the OP to tell us more about where the ps files are located, e.g. whether they're in nested sub-dirs, on a remote server, etc.


Thanks for that. Its been a verrry long time since I've messed around with shell scripting.

Assumptions were all there was to go on - but I believe it may be best to provide a scripted method that hangs around versus one that has to be remembered and retyped if this becomes a frequent event.
 

balamw

Moderator emeritus
Aug 16, 2005
19,366
979
New England
This assumes the ps files all end in ".ps", and they are all in the current directory. To improve the script, though, we'd need the OP to tell us more about where the ps files are located, e.g. whether they're in nested sub-dirs, on a remote server, etc.

You could also just get rid of the for loop and replace with find and xargs if things are more complicated. (e.g. you need to recurse a directory tree)

Read here for some examples http://en.wikipedia.org/wiki/Xargs or just "man xargs"

B
 

ign

macrumors member
Original poster
Mar 16, 2004
37
1
Firenze
thanks a lot for all the suggestions. I had tried with automator and it actually worked even though the resulting pdf had 5x the size of the pdf created doing it one by one in finder.

Anyway I'll go for the terminal command which seems the most robust and fast solution. I'll play with it and see if I make it, I'll let you know !

cheers
 

gorn

macrumors member
Jun 17, 2009
47
0
Code:
find . -name \*.ps -exec pstopdf {} \;

that will find them in subdirectories too.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.