?
Solved

HotKey to run script in Safari

Posted on 2011-09-13
4
Medium Priority
?
339 Views
Last Modified: 2012-05-12

I'm trying to write a little applescript or MAC automater action that I can trigger with a hot key.

The html code for the website is below and in the area "<input name="EmployeeNumber" type="text" size=8>"

I need the program to enter 4-digits then hit "enter."

I'm on a MAC with Snow Leopard usually running Safari. Thanks.


<form name="SignIn" method="post" action="http://fmweb/.....xsl">
    <p>
        <input type="hidden" name="-script" value="SetOfficeLocator" />
        <input type="hidden" name="-db" value="TRG%20Check%20In%20Log" />
        <input type="hidden" name="-lay" value="Webcheckin" />
        <input type="hidden" name="-grammar" value="fmresultset" />
        <input type="hidden" name="-encoding" value="UTF-8" />
        <input type="hidden" name="InOut" value="In">
    </p>
    <p>
        <font face="Arial, Helvetica, sans-serif" size="2">Enter (optional) from where (e.g.,
            client meeting, doctor, lunch).</font>
        <input name="Return When" type="text" value="" size="25">
        <br>
    </p>
    <p>
        <font face="Arial, Helvetica, sans-serif" size="2">Please enter your employee number</font>
        <input name="EmployeeNumber" type="text" size="8">
        <font face="Arial, Helvetica, sans-serif" size="2">&nbsp;then <font color="#FF0000">
            click-&gt;</font></font>
        <input type="submit" name="-new" value="Sign In" />
        <br>
    </p>
    </form>

Open in new window

0
Comment
Question by:wilcor14
  • 2
  • 2
4 Comments
 
LVL 83

Expert Comment

by:leakim971
ID: 36530928
try this :
<script>
window.onload = function() {
    document.getElementsByName("EmployeeNumber")[0].value = "1234"; // 4 digits
    document.forms[0].submit(); // ENTER KEY
}
</script>

Open in new window

0
 

Author Comment

by:wilcor14
ID: 36530999
Thanks for the info. This will execute on page load right? Is there a way to call this with a hotkey such as alt z or something? Thanks.
0
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 36531127
document.onkeydown = function(e) {
    if(window.event) {
        var ctrlPressed = window.event.ctrlKey;
        var key = window.event.keyCode;    
    }
    else {
        var ctrlPressed = e.ctrlKey;
        var key = e.whiche;    
        
    }
    if( key == 90 && ctrlPressed) {
        document.getElementsByName("EmployeeNumber")[0].value = "1234"; // 4 digits
        document.forms[0].submit(); // ENTER KEY
    }
}

Open in new window

0
 

Author Closing Comment

by:wilcor14
ID: 36554637
Sorry for the delay. Needed some time to test. Works perfect thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question