applescript: print rtf to pdf etc.

Ken Ray kray at sonsothunder.com
Sat Nov 18 20:19:18 EST 2006


On 11/18/06 12:20 PM, "Jim Ault" <JimAultWins at yahoo.com> wrote:

> On 11/18/06 9:57 AM, "R. Hillen" <mail at richard-hillen.de> wrote:
> 
>> Hello list,
>> 
>> On Mac OSX I want to print some rtf-Files bfrom runrev. I assume,
>> that is a job for applescript. As I don't know about apple-scripting:

Actually you can do it with the shell's "convert" applet... it works for
text and RTF files perfectly. Here's the code (watch the line wraps):

on mouseUp
  answer file "Select a file to turn into a PDF:"
  if it <> "" then
    put it into tSrc
    set the itemDel to "/"
    put item -1 of tSrc into tFile
    replace "." with "/" in tFile
    put tSrc into tDest
    put item 1 of tFile & ".pdf" into item -1 of tDest
    stsMakePDF tSrc,tDest
  end if
end mouseUp

on stsMakePDF pSrcPath,pDestPath
  switch (the platform)
  case "MacOS"
    if isOSX() then
      set the cursor to watch
      put "/System/Library/Printers/Libraries/convert" into tConvertApp
      get shell(tConvertApp && "-f" && q(pSrcPath) && "-o" && q(pDestPath)
&& "-j application/pdf")
      if it = "" then
        return "OK"
      else
        return "Error : " & it
      end if
    else
      return "Error : stsMakePDF only works on Mac OS X."
    end if
    break
  default
    return "Error : stsMakePDF only works on Mac OS X."
    break
  end switch
end stsMakePDF

function isOSX
  set the itemDel to "."
  return (item 1 of the systemVersion >=10)
end isOSX

function q pWhat
  return quote & pWhat & quote
end q

Enjoy!


Ken Ray
Sons of Thunder Software, Inc.
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com





More information about the Use-livecode mailing list