Solved

HotKey to run script in Safari

Posted on 2011-09-13
4
325 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 82

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 82

Accepted Solution

by:
leakim971 earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Information security is a multi-billion dollar industry. Just as lucrative is the black market industry which trades stolen identities, credit card numbers and software exploits all over the world. Nothing is hack-proof. The best one can do is make …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now