Filling In a Web Page Form Using Automator

You can use JavaScript in Automator to fill in a web page form. If you make this a Quick Action you can access it from the menu bar or as a keyboard shortcut. This can help speed up situations where you need to fill in the same form every day.

Here is the sample code:

var safari = Application("Safari");
safari.includeStandardAdditions = true;
var jsScript = "";
jsScript += "document.getElementsByName('firstname')[0].value ='A';";
jsScript += "document.getElementsByName('lastname')[0].value ='B';";
jsScript += "document.getElementsByName('zipcode')[0].value ='12345';";
jsScript += "document.getElementsByName('bodytext')[0].value ='This is a test.';";
jsScript += "document.forms[0].submit();";
safari.doJavaScript(jsScript, { in: safari.windows[0].currentTab });

Comments: 9 Responses to “Filling In a Web Page Form Using Automator”

    Douglas Brace
    5 years ago

    Pretty cool! Thank you for sharing this. Something for others to keep in mind is that websites that use CAPTCHAs may cause this to not work (or work as smoothly as we may want).

    Dana Stevens
    5 years ago

    A great video. Made the time I spent learning the basics of Javascript worthwhile. Probably doesn't appeal to a significant portion of your viewers but I really appreciate it. Thanks Gary.

    Bill Sinclair
    5 years ago

    Woah — way too geeky. All this effort to enter normal details?
    all the best

    Dana Stevens
    5 years ago

    Gary,
    You said you could do this in either Automator or Script Editor. Would it be possible to post a script editor version? If you don't have time to fool with it I certainly understand. Thanks. Dana

    5 years ago

    Dana: The JavaScript is the same. Using Script Editor is just like using Automator when you are just including a script and no other actions.

    Dana Stevens
    5 years ago

    Thanks Gary. I've tried to adapt the script to see if I could make a script using JavaScript that does the same thing that one of my more complicated AppleScripts accomplishes. I've had success with the modified code when putting the code in the JavaScript console but have not had much luck with the code when using Script Editor. I'll keep working on it. Thanks for posting the video that gave me the inspiration to try. Dana

    Dana Stevens
    5 years ago

    Gary, I did get my modified code to work using Script Editor. Had to change my thinking a bit but your comment that "The JavaScript is the same" and a bit of internet searching put me on the right track. I don't think you'll make a JavaScript convert out of me just yet but this post may have taken me down that path. Thanks again for making the original post and for being there for us. I'll try to make comments only during normal business hours from now on. Dana

    EA Platt
    5 years ago

    Gary -- would this work with a PDF file that had fill in the blanks?

    5 years ago

    EA: No. It relies on web pages being scriptable (JavaScript). PDFs are not.

Comments Closed.