Jump to content

How can i execute different scripts if specific websites/pages open up in firefox ?


Recommended Posts

Hi im new to Autoit and i working on a project. I created something really simple where i put macros containing mouseclicks and keyboard presses to specific hotkeys while im working on webpages in firefox. Something like this :

HotKeySet("{0}","g")


Func q()
MouseClick("left",126,29,1,2)
MouseClick("left",28,314,1,2)
Send("{PGDN}{PGDN}{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}")
MouseClick("left",208,294,1,4)
MouseClick("left",205,399,1,2)

EndFunc

But i always wondered if there is a way to automate that in a way. For example if a specific website opens up (http://www.autoitscript.com/forum) then it should execute the above, and so on with other websites. (Note i dont mean in a malicious way, i just wanted to keep it abstract)

So if website 1 turns up execute script a, website 2 execute script b etc. Is this Possible ?

I use SciTE Version 3.4.1 with au3recorder. I looked at the Help file mentioned but i dont actually know what to look for :/

Link to comment
Share on other sites

Hi there, thanks i did. But that doesnt help me. I read through the commands but there doesnt seem to be one that would help me. Most of them execute stuff. But i need something to read out the adressbar and automatically execute a function as simple as possible.

I even thought about improvising since i only know the basic commands like mouseclick (), send () etc. Basically copy pasting the adressbar and searching in an open notepad file for that adress for the appropiate hotkeys i need to press. But i thought maybe there is a way the script does that for me, pressing his own hotkeys so it executes its own functions. I´m really lost here :(

I also used the au3 recorder and everytime i use it to record my mouseclicks it would create a command _WinWaitActivate "www.etc.com/etc/etc". So i thought autoit is actually able to know what page is active so it shouldn´t be hard to have him execute a simple script based on that or ? But the command doesnt work and i dont if it works that way anyways.

Maybe someone is willing to help me out ?

Link to comment
Share on other sites

Example _FFCmd usage from FF.au3 taken from http://english.documentation.ff-au3.thorsten-willert.de/ff_functions/_FFCmd.php

#Include <FF.au3>

 _FFConnect()

If _FFIsConnected() Then
    ; href of the current page
    $sHref = _FFCmd(".location.href")
    If Not @error Then MsgBox(64,"Current href:",$sHref)

    _FFOpenURL("http://ff-au3-example.thorsten-willert.de/")
    ; href from an image link
    $sHref = _FFCmd(".images[0].parentNode.href")
    If Not @error Then MsgBox(64,"Href of the first image-link:",$sHref)

    ; title of the current page
    $sTitle = _FFCmd( ".title")
    If Not @error Then MsgBox(64,"Title of the current page:",$sTitle)

    ; browser version
    $sVersion = _FFCmd("navigator.userAgent")
    If Not @error Then MsgBox(64,"Browser version:",$sVersion)
Else
    MsgBox(64,"Error:","Can't conncect to FireFox")
EndIf
Link to comment
Share on other sites

Maybe try WinExists  https://www.autoitscript.com/autoit3/docs/functions/WinExists.htm

If WinExists("AutoIt Forums") Then

  WinActivate("AutoIt Forums")

  (DO SOMETHING)

EndIf

It did the trick for me - i am checking if certain window exists (in that case - window containing whole/part name of webpage), set this window as active and do the auto-magic.

Of course it isnt running many scripts, just 1 script with different functions for different windows. During script execution (eg when your mouse moves etc) you should not touch any controls (mouse, keyboard...).

Edited by misioooo
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...