I am relatively new to AppleScript and I'm trying to find a way to programmatically enter a filename into a Save as PDF... dialog in Firefox.
I've gotten this far from searching the web. I've turned on the Accessibility Inspector in Xcode and I can inspect the various form elements.
on run {input, parameters}
tell application "Firefox" to activate
tell application "System Events"
tell process "Firefox"
click menu item "Print…" of menu "File" of menu bar 1
click menu button "PDF" of window "Print"
keystroke "S"
keystroke return
end tell
end tell
return input
end run
My situation is this: I have Firefox open with 20 tabs and I want to use AppleScript to save each tab as a pdf file with a "prefix"+"number" filename, e.g. "foo001.pdf", "foo002.pdf", etc.
- How do I set up a variable that I can increment in AppleScript?
- How do I enter a programmable filename into the appropriate field in the Save as PDF... dialog?
- Assuming that the script starts with the currently active tab in Firefox, how can I test when I've reached the last tab? (I suppose I could just let it select the "next" tab until it gets an error)
Thanks in advance.
See script where it does that with
keystroke "newFileName"
.Maybe you can find a way to check if the next tab exists (on the right side) before switching to it so you know when to stop the script. At the end it just goes to the first tab (no error).
To see some useful code snippets, ctrl-click into a script. It also has repeat routines which may help you to archive the looping.
I can't help more, but here a working boiler plate:
Part 1 stores the current page as pdf with "newFileName" as name and the second part goes to the next tab.