Note sure. If it was the case, the script result should be “save as panel can’t open” (unless you’ve change it!).
Same thing if it can’t find the Export menu.
Does the ‘Save As’ panel opens or not at all?
I spent over an hour attempting to get my script to work reliably with the suggested solutions, but none worked reliably. So, I’m going to give up on this one. My original script is a bit slow and kludgey, but it does work reliably, and I’ll continue using that.
Thanks everyone for your suggestions–I greatly appreciate your help.
@peavine, are you interested in a wkhtmltopdf based solution? It’s a command line tool to render HTML into PDF. You could either have Safari save the html or just pull it with curl. Quick here on slow intel hardware.
--https://blog.harawata.net/2011/06/convert-html-files-to-pdf-using-web-kit.html?m=1
on run
set htmls to choose file with prompt "PDFに変換するHTMLファイルを指定してください。" of type {"public.html"} with multiple selections allowed
my convertHtmlToPdfList(htmls)
end run
on open htmls
my convertHtmlToPdfList(htmls)
end open
on convertHtmlToPdfList(htmls)
tell application "Finder"
set cmd to POSIX path of (path to me) & "Contents/MacOS/wkhtmltopdf"
--The above line expects you to place the executable in the Contents/MacOS/ directory inside the application package.
--I would replace this with a posix path to the wkhtmltopdf binary.
--i.e. set cmd to "/usr/local/bin/wkhtmltopdf"
repeat with html in htmls
if (name extension of html is "html") then
my convertHtmlToPdf(cmd, html)
end if
end repeat
end tell
end convertHtmlToPdfList
on convertHtmlToPdf(cmd, html)
tell application "Finder"
set htmlName to name of html
set {dir, htmlUrl, pdfName} to {POSIX path of (container of html as alias), URL of html, text 1 thru -5 of htmlName & "pdf"}
end tell
do shell script "\"" & cmd & "\" \"" & htmlUrl & "\" \"" & dir & pdfName & "\""
end convertHtmlToPdf