How to use AppleScript to enter a filename in Firefox Save As dialog?
NickName:Mac471 Ask DateTime:2015-06-11T12:26:28

How to use AppleScript to enter a filename in Firefox Save As dialog?

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.

  1. How do I set up a variable that I can increment in AppleScript?
  2. How do I enter a programmable filename into the appropriate field in the Save as PDF... dialog?
  3. 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.

Copyright Notice:Content Author:「Mac471」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/30771572/how-to-use-applescript-to-enter-a-filename-in-firefox-save-as-dialog

Answers
user3577225 2015-06-12T23:19:19

\n How do I set up a variable that I can increment in AppleScript?\n\n\nset counter to 0 # setup counter\nset counter to counter + 1 # increment counter\n\n\n\n How do I enter a programmable filename into the appropriate field in\n the Save as PDF... dialog?\n\n\nSee script where it does that with keystroke \"newFileName\" .\n\n\n Assuming that the script starts with the currently active tab in\n Firefox, how can I test when I've reached the last tab? (I suppose I\n could just let it select the \"next\" tab until it gets an error)\n\n\nMaybe 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).\n\n\n\nTo see some useful code snippets, ctrl-click into a script. It also has repeat routines which may help you to archive the looping.\n\nI can't help more, but here a working boiler plate: \n\n\n\nPart 1 stores the current page as pdf with \"newFileName\" as name and the second part goes to the next tab. \n\ntell application \"Firefox\" to activate\ndelay 0.25\n\ntell application \"System Events\"\n\n tell process \"Firefox\"\n set frontmost to true\n\n click menu item \"Print…\" of menu \"File\" of menu bar 1\n delay 0.25\n\n click menu button \"PDF\" of window \"Print\"\n delay 0.1\n keystroke \"S\"\n delay 0.1\n keystroke return\n\n repeat until window \"Print\" exists\n delay 0.5\n end repeat\n\n keystroke \"newFileName\"\n keystroke return\n\n end tell\n\nend tell\n\n\ntell application \"System Events\"\n tell process \"Firefox\"\n set frontmost to true\n # let's go to the next tab\n # (# 123 goes back) \n key code 124 using {command down, option down}\n end tell\nend tell\n",


More about “How to use AppleScript to enter a filename in Firefox Save As dialog?” related questions

How to use AppleScript to enter a filename in Firefox Save As dialog?

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 tur...

Show Detail

How to open a Save As dialog in MS Word showing SharePoint Online Locations by using VBA or AppleScript?

I have a Word Template containing VBA in a content type on SharePoint online. When a new document is created based on this content type Word desktop starts and VBA opens a dialog. The user can ente...

Show Detail

Applescript Change To Folder Save Dialog

I'm trying to automate opening and saving a file in applescript. I can't seem to get consistent results with the save dialog though. Is it possible to change a save dialog to a specific folder in

Show Detail

Filename incorrect in save dialog - Firefox

I am redirecting to an image with a Location header from PHP, and in firefox when you view the image and right click to save it prompts to save with the name of the PHP redirect script, not the nam...

Show Detail

AppleScript "Save As" dialog?

What is the AppleScript code for a "Save As" dialog with a custom file type extension? I know the code for Open dialog: set theFiles to (choose file of type {"set"} with prompt "Save As File" wit...

Show Detail

Override Firefox's Default Filename in the "Save Page As" Dialog

I want to write a Firefox Add-on which removes some special characters from the default filename (highlighted in red in the image below) in the "Save Page As" dialog in Firefox. Does the Firefox SD...

Show Detail

How to Disable Save As dialog in Firefox

How to disable Save As dialog while pressing Ctrl+S Description: I am developing one web application.Here When i am going to form submitting using "Ctrl+S",In Firefox before submitting "save As d...

Show Detail

Applescript to Control Photoshop Save Dialog Box

How are you? I've created an applescript automation to save files in .JPG while the Save Dialog Box is open. (So I can control the name of the saved files) Is there a way to control the Save Dial...

Show Detail

Applescript: Batch save files in Preview without save dialog

thanks in advance for your help. New to Applescript. Trying to open in Preview all files in folder and save them. The problem is that saving pops up a dialog half the time, which requires me to sit

Show Detail

Applescript how to display a dialog with text and a variable

I need to display a applescript dialog with text and a number by which i mean the text that it displays would be text and a varible like this display dialog "Enter spelling" and repeatnum buttons{"...

Show Detail