Hey Yvan,
(1) It seems that close access (open for access file savePath) is faster than do shell script "touch " & quoted form of POSIX path of savePath
True.
(2) At first run I'm forced to add the instruction tell application "PDFpenPro" to activate before calling the handler.
Yeah, I've fixed this in my final script.
(3) As I never used PDFpenPro before testing your script, I used save document 1 in file savePath as I do most of the time.
After receiving your message, I tried to remove it and the script works well without "file".
Strange. I need “file”, although I'm not leaving the file open as you are.
(5) When there is already a true PDF named "test.pdf", the script fails - after 1 or some run - with the error : error "Erreur dans PDFpenPro : Il est impossible d’obtenir document 1. Index non valable." number -1719 from document 1
I seem to be getting around that successfully by setting the eof of the file to 0.
So far this script is working flawlessly whether on first launch of PDFPenPro or with it running.
------------------------------------------------------------------------------
set savePath to (path to desktop as text) & "test.pdf"
------------------------------------------------------------------------------
# Uncomment if you want to prevent the script from overwriting ~/Desktop/test.pdf
------------------------------------------------------------------------------
# try
# alias savePath
# error "test.pdf already exists at that location!"
# on error e number n
# if n ≠ -43 then error e number n
# end try
------------------------------------------------------------------------------
touchFile(savePath) of me
tell application "PDFpenPro"
if not running then
activate
repeat while (path to frontmost application as Unicode text) does not contain "PDFPenPro"
delay 0.5
end repeat
end if
createOnePageBlankInPDFPenPro() of me
delay 0.1
save document 1 in file savePath
end tell
------------------------------------------------------------------------------
on createOnePageBlankInPDFPenPro()
tell application "System Events" to tell process "PDFpenPro"
set frontmost to true
keystroke "n" using {command down}
end tell
end createOnePageBlankInPDFPenPro
------------------------------------------------------------------------------
on touchFile(filePath)
try
close access fileRef
end try
set fileRef to open for access filePath with write permission
set eof of fileRef to 0
close access fileRef
end touchFile
------------------------------------------------------------------------------
As always – thanks for the help. :)