I am trying to make a script that opens an swf file with safari and then print it as a pdf using the built in "Save as PDF" feature. So far my code looks like this:
set appleworksFolder to choose folder
tell application "Finder"
set folderItems to (files of entire contents of appleworksFolder)
repeat with I from 1 to number of items in folderItems
set the_doc to item I of folderItems
set doc_name to name of the_doc as text
tell application "Finder"
set the clipboard to doc_name & ".pdf"
end tell
if name of the_doc is not ".DS_Store" then
try
tell application "Safari"
activate
open the_doc
tell application "System Events"
tell application process "Safari"
delay 1
click menu item "Print…" of menu "File" of menu bar 1
delay 5
click menu button "PDF" of window "Print" of application process "Safari" of application "System Events"
delay 1
click menu item "Save as PDF…" of menu "PDF" of menu button "PDF" of window "Print" of application process "Safari" of application "System Events"
delay 1
keystroke "v" using command down
click button "Save" of window "Save" of application process "Safari" of application "System Events"
delay 8
keystroke "w" using command down
delay 0.5
end tell
end tell
end tell
end try
end if
end repeat
end tell
This works up to seeing the print dialogue, but it doesn't seem to click the pdf menu button so doesn't get any further than this. I was wondering if this is a problem with mountain lion not letting me use applescript to control buttons, and if so, is there a fix for it? Any help would be greatly appreciated!