View Single Post
Hi Ken,

thanks for sharing that code! It is wonderful for pasting the attachment!

I am trying follow the previous ideas and am parsing the content of a note and pass that content as command line argument to a python script (create_latex_pdf.py). This seems to work. The goal of the python script is to generate a pdf file which can then be used as an attachment in the cell of the selected row.

Part 1: Applescript

Code:
set lstNote to {}
tell application id "OOut" to set lstNote to note of selected rows of front document
set strNote to lstNote as text

tell application "Finder" to get folder of (path to me) as Unicode text
set presentDir to POSIX path of result

set py to "create_latex_pdf.py"
set calldir to "python " & quoted form of presentDir & py & " " & strNote
do shell script calldir
When I do this, I get no error, a temp.ps file is created, but it has 0 bytes.

Part 2: Python script

See the python code below. When I run it from the terminal, it works and generates a pdf file as it should. However, when called from applescript I can't see what it is doing or where / why it stops. I'd appreciate pointers.

Code:
str_latex_note = sys.argv[1]
preamble = """\documentclass{article}
\usepackage{amsmath,amssymb}
\pagestyle{empty}
\\begin{document}
{\huge
\[
 %s
 \]
}
\end{document}"""% (str_latex_note)

cur_path = r'/Users/myfolder/Library/Scripts/OO_latex'
cur_file = "temp.tex"
fobj = open(os.path.join(cur_path, cur_file), 'w')
fobj.writelines(preamble)
os.chdir(cur_path)
cmd = 'latex temp.tex'
print cmd
os.system(cmd)
    
cmd2 = 'dvips -E -f -X 1200 -Y 1200 temp.dvi > temp.ps'
os.system(cmd2)
    
cmd3 = 'epstopdf temp.ps'
os.system(cmd3)