ps2pdf droplet

The long running gag around here is I use old software that works with old hardware. Fun. Recently I was sent a PostScript file to output to film, but the version of Distiller I use choked on it. Illustrator CS2 could open it, but unbeknownst to me it only imports the first page. More fun.

Inkscape will import PostScript files and will ask you which page you’d like to open. Unfortunately Inkscape version 1.1 on macOS will not because… reasons?

Luckily the tool it uses to convert PS to PDF still works– ps2pdf. If you have Ghostscript installed you should have ps2pdf available as well.

This AppleScript is set to use ps2pdf installed via macports.

Of note is replacing the “.ps” extension using text item delimiters. Relevant lines being:

set my text item delimiters to {"."}
...
set target_path to (text items 1 thru -2 of source_path) & "pdf" as string

I’ve seen people write complete paragraph weight routines to do that, so tuck this away in your bag-of-tricks. 😉

(*
http://strawhousepig.net/
*)

-- Path to your ps2pdf script.
property path2ps2pdf : "/opt/local/bin/ps2pdf " -- Don't forget the trailing space!

on run
  tell application "Finder"
    try
      set cwd to folder of window 1
    on error
      set cwd to home
    end try
  end tell
  open {choose file with prompt ¬
    "Choose PostScript files to convert:" default location cwd as alias with multiple selections allowed}
end run
on open the_files
  set my text item delimiters to {"."}
  repeat with _file in the_files
    if name extension of (info for _file) is "ps" then
      try
        set source_path to POSIX path of (_file as alias)
        set target_path to (text items 1 thru -2 of source_path) & "pdf" as string
        do shell script path2ps2pdf & quoted form of source_path & " " & quoted form of target_path
      on error theErr
        if theErr is not "User canceled." then display dialog theErr
      end try
    end if
  end repeat
end open

Leave a Reply

Your email address will not be published. Required fields are marked *