Hi guys, I have a bunch of text file I want to open one at a time in TextEdit, print as PDF and, as soon as the PDF is made on the Desktop, get “Preview” to open it. I have a hard time getting preview to only try to open the PDF when it’s actually ready. Right now I’m getting “Preview got an error: Can’t get file "width_9.1_height_6.07_e.txt.pdf".”"
Thanks for your help.
tell application "Finder"
activate
set my_folder to (choose folder)
set my_text_files to (every item in my_folder)
repeat with this_text_file in my_text_files
tell application "TextEdit"
activate
open this_text_file
set my_name to get (characters 1 thru -5 of (get the name of this_text_file) as string)
ignoring application responses
print this_text_file with properties {target printer:"Adobe PDF 8.0"} without print dialog
delay 1
end ignoring
set file_to_open to my_name & ".txt.pdf" as string
tell application "Preview"
activate
repeat until file file_to_open of desktop exists
end repeat
open file file_to_open of desktop
end tell
end tell
end repeat
end tell