Jump to content

Get script to ignore page title and act on the active window regardless of its title


Recommended Posts

I'm trying to get a script to do the following:

1. Open Firefox Tools menu "{ALT}+t"

2. Open the Page Info sub-menu "i"

3. Move the focus to the MEDIA button "{RIGHT}"

4. Scroll down to select the 6th image "{DOWN}" repeated 6 times

5. Open the SAVE AS dialogue box "{ALT}+a"

I have two problems:

1. The script works to the ALT+a line when I specify the PAGE TITLE in the "WinWaitActive command".

But the SAVE AS box does not open. There are no error messages or error sounds.

2. I can't get the script to run unless I have specified the page title of the window in the "WinWaitActive command.

My main problem is getting the script to work no matter what the page title is. I don't know how to do this, as the script needs to know what window the command is to be applied, so if I leave this portion blank or empty, nothing happens.

What I want to tell the script is: "Ignore the "PAGE TITLE" and run the script on the active window." This window will always be the "Page Info" box, but it will have a different title for each image.

Here's my script. I have no idea what the top commands do except perhaps to set the environment, I've left them in from the sample script supplied with AutoIt. My script begins from the line "Start of Script"

--------------

[script=BEGIN]

--------------

' Example WSH Script (VBScript)

' -----------------------------

' Require Variants to be declared before used

' -------------------------------------------

Option Explicit

' Declare Variables & Objects

' ---------------------------

Dim oShell

Dim oAutoIt

' Initialise Variables & Objects

' ------------------------------

Set oShell = WScript.CreateObject("WScript.Shell")

Set oAutoIt = WScript.CreateObject("AutoItX3.Control")

' Start of Script

' ---------------

' Wait for the Firefox window to become active

oAutoIt.WinWaitActive "All sizes | oldsmobile | Flickr - Photo Sharing! - Mozilla Firefox", ""

' Send some keystokes to firefox

' ------------------------------

oAutoIt.Send "{ALT}+t"

oAutoIt.Sleep 500

oAutoIt.Send "{i}"

oAutoIt.Sleep 500

oAutoIt.Send "{RIGHT}"

oAutoIt.Send "{TAB}"

oAutoIt.Send "{DOWN}"

oAutoIt.Send "{DOWN}"

oAutoIt.Send "{DOWN}"

oAutoIt.Send "{DOWN}"

oAutoIt.Send "{DOWN}"

oAutoIt.Send "{DOWN}"

oAutoIt.Send "{ALT}+a"

WScript.Quit

--------------------

[script=END]

--------------------

I'm running Windows XP SP3 plus latest updates, on a HP P4 3.2 with 4GB DDR2 RAM, Firefox 20.0.1 with Javascript enabled

To summarize:

1. The line "oAutoIt.Send "{ALT}+a"" doesn't work. How can I solve that?

2. How can I code the script and tell it to ignore the page title and work on the active window regardless of page title?

You might want to try it on the following web page - whick is my Flickr page:

http://www.flickr.com/photos/fruit_and_nut/8663623973/sizes/l/in/photostream/

After running the script, you'll need to click the Page Info window to make it active.

Thank you for considering this... :sweating:

Edited by fredemeister
Link to comment
Share on other sites

fredemeister,

Welcome to the Autoit forums. :)

I think you've made a great first post with details of the problem that your experiencing. Well done but maybe you could edit your post and add the code tags for better readabillity. I do have a couple of questions. If the window does open after running the script

After running the script, you'll need to click the Page Info window to make it active.

and you have to click the window to activate it then perhaps you need to activate the window first? Try:
WinActivate()
before the WinWaitActive statement. If the object call in VbScript isn't working properly than please consider using an AutoIt script instead. I'm sorry if that isn't much help but I'll try running your example and report back.

*Edit - Unfortunately it seems that I lack some prerequisites necessary to run your script. I've never used AutoIt in a VbScript before because it kinda seems like a step backwords. Anyway if your syntax is correct than I see no reason for your script not to function properly therfore I've drawn the conclusion that a step is missing and your method seems a little unorthodox not that it isn't a worthy attempt at automation. If you don't care to install an extension in firefox than look into the Firefox UDF which uses the MozRepl addon and report back any problems you encounter. Just some alternative approaches. ;)

This might answer the question that is in this topics title.

Dim $hActiveWindow = WinGetHandle("[ACTIVE]", "")

Anonymous

Edited by Decipher
Spoiler

censored.jpg

 

Link to comment
Share on other sites

fredemeister,

Welcome to the Autoit forums. :)

I think you've made a great first post with details of the problem that your experiencing. Well done but maybe you could edit your post and add the code tags for better readabillity. I do have a couple of questions. If the window does open after running the script and you have to click the window to activate it then perhaps you need to activate the window first? Try:

WinActivate()
before the WinWaitActive statement. If the object call in VbScript isn't working properly than please consider using an AutoIt script instead. I'm sorry if that isn't much help but I'll try running your example and report back.

*Edit - Unfortunately it seems that I lack some prerequisites necessary to run your script. I've never used AutoIt in a VbScript before because it kinda seems like a step backwords. Anyway if your syntax is correct than I see no reason for your script not to function properly therfore I've drawn the conclusion that a step is missing and your method seems a little unorthodox not that it isn't a worthy attempt at automation. If you don't care to install an extension in firefox than look into the Firefox UDF which uses the MozRepl addon and report back any problems you encounter. Just some alternative approaches. ;)

This might answer the question that is in this topics title.

Dim $hActiveWindow = WinGetHandle("[ACTIVE]", "")

Anonymous

Firstly, thank you for your time and trouble in replying to my problem, I appreciate it very much. :thumbsup:

<< edit your post and add the code tags for better readabillity. >>

Sorry, I don't know what you mean by "CODE TAGS".

I've added your last code into my script, but the "$" is causing an error message - "invalid character" on that line and that character.

The lines were causing issues, so I removed them and condensed the script - which now appears as below.

[scriptStart]

' Example WSH Script (VBScript)

' Require Variants to be declared before used

Option Explicit

' Declare Variables & Objects

Dim oShell

Dim oAutoIt

' Initialise Variables & Objects

Set oShell = WScript.CreateObject("WScript.Shell")

Set oAutoIt = WScript.CreateObject("AutoItX3.Control")

' Start of Script

' Wait for the Firefox window to become active

' oAutoIt.WinWaitActive "All sizes | oldsmobile | Flickr - Photo Sharing! - Mozilla Firefox", ""

WinActivate()

Dim $hActiveWindow = WinGetHandle("[ACTIVE]", "")

' Send some keystokes to firefox

oAutoIt.Send "{ALT}+t"

oAutoIt.Sleep 500

oAutoIt.Send "{i}"

oAutoIt.Sleep 500

oAutoIt.Send "{RIGHT}"

oAutoIt.Send "{TAB}"

oAutoIt.Send "{DOWN}"

oAutoIt.Send "{DOWN}"

oAutoIt.Send "{DOWN}"

oAutoIt.Send "{DOWN}"

oAutoIt.Send "{DOWN}"

oAutoIt.Send "{DOWN}"

oAutoIt.Send "{ALT}+a"

WScript.Quit

[scriptEnd]

<< If the object call in VbScript isn't working properly than please consider using an AutoIt script instead. >>

Umm ... I thought I was using AutoIt. That shows how much of a clunker I am ... :sorcerer:

<< a step is missing and your method seems a little unorthodox >>

As mentioned I'm an absolute beginner with scripting, this is the first time I've tried to do any scripting.

I would much prefer to avoid scripting completely as I'm not good at picking up new concepts.

I searched to see if there's something like this in Firefox extensions, but didn't know what to search for, so my attempts were interesting, but unfruitful. If someone is able to suggest something I'd gladly try it.

But thank you again ...

Link to comment
Share on other sites

fredemeister,

If the extension of your script isn't .au3 then your not using AutoIt in a traditional mannor. The $ conflict is undoughtfuly because your using it in a VbScript which may or not support that particular syntax in variable names. The first thing your going to want to do is download the full AutoIt3 package. Get it from here -> http://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3-setup.exe

I think that everyone can benefit from a scripting experience because it exposes so many new concepts and helps a user to better understand their computer. I started out with batch scripting then advanced batch scripting, failed at C++, moved on to Python, Learned HTML, Javascript, CSS, and then finally discovered AutoIt which helped me to become a better programmer from that point on. It really gave me the skill that I needed to master Javascript. Its portable and has great GUI creation capabillities so even someone with your experience can create a basic program that a user can interface with. Not to mention its well documented. Try opening up your VbScript in notepad to highlight a builtin function name and press F1 and see if your instantly provided with the relevant comprehensive documentation you'll needed to implement it. <- Thats not gonna happen but in AutoIt's customized version of the Scite Code Editor it does along with command completion, etc.. I used to think that VbScript had to much overhead until I learnt AutoIt now I can grab any code snippet thats in any high level interperted non-staticly typed programming language and make it work with ease, well that and a little Google. I'm just trying to get you hyped up about what your doing because you should be having fun! ;)

Later you might want to come back and get the full AutoIt3 Customized Scite -> http://www.autoitscript.com/site/autoit-script-editor/downloads/

Now to the problem at hand, I've converted your script to native AutoIt. Select Popup and copy and paste this file into notepad. Save the file using the .au3 extension.

;Example WSH Script (VBScript)
;Require Variants to be declared before used
Opt("MustDeclareVars", 1) ;Option Explicit
Opt("WinTitleMatchMode", 2) ; Match any substring in a windows title i.e. the following title: (Mozilla Firefox - Whatever tab is active.)

; The syntax for comments is the ";" semicolon
;Declare Variables & Objects

#cs  <- This denotes the start of a multi line comments
Dim $oShell
Dim oAutoIt


' Initialise Variables & Objects

None of this is necessary any longer.

Set oShell = WScript.CreateObject("WScript.Shell")
Set oAutoIt = WScript.CreateObject("AutoItX3.Control")

' Start of Script

' Wait for the Firefox window to become active
#ce

; Get a handle to the window first.
Dim $hFirefox = WinGetHandle('WinWaitActive "All sizes | oldsmobile | Flickr - Photo Sharing! - Mozilla Firefox', "")
WinActivate($hFirefox)
WinWaitActive($hFirefox, "") ; Now wait until its actually the active window.


; I'm not sure this is necessary at the moment.
;Dim $hActiveWindow = WinGetHandle("[ACTIVE]", "")

;Send some keystokes to firefox

Send("{ALT}+t") ; You may have noticed that function params must be enclosed in parenthesis
Sleep(500)
Send("{i}")
Sleep(500)
Send("{RIGHT}")
Send("{TAB}")
Send("{DOWN}")
Send("{DOWN}")
Send("{DOWN}")
Send("{DOWN}")
Send("{DOWN}")
Send("{DOWN}")
Send("{ALT}+a")
Exit ;WScript.Quit

The code tags:

You're using the proper syntax to specify the BBcode so all you need to do in your most recent post is replace the "ScriptStart" with autoit but remember to remove the text customizations like the underline. The square brackets must remain. To specify the ending tag which is also required then replace "ScriptEnd" also but precede autoit with a solidus. It should look like this without the asterick. [/auto*it] Also note that there is an "A" button for this in the quick reply editor. Like the code syntax highlighted examples I gave above you can then click on the function names to view the online documentation.

So install the AutoIt package, test the script then report back any problems bro. :)

Anonymous

Spoiler

censored.jpg

 

Link to comment
Share on other sites

Thanks for the above. created a new AutoIt file and copied the contents of the box to that. Tried it on the Flickr page, but didn't work at all.

Changed lines as shown below, and got it to work on any active page, but the ALT+a still doesn't activate.

This line:

" Dim $hFirefox = WinGetHandle('WinWaitActive "All sizes | oldsmobile | Flickr - Photo Sharing! - Mozilla Firefox', "")

changed to:

Dim $hFirefox = WinGetHandle('ACTIVE', "")

as I wanted the ACTIVE window rather than the one I specified originally - that was just to get it to work on that specific page.

And this line:

"; Dim $hActiveWindow = WinGetHandle("[ACTIVE]", "")"

which was commented out, I made active, and hey presto. The error message I received was that I was calling a variable without it being specified. That made sense, as I'd uncommented the "call" to the active page, but had the specified page as the variable. Small things trip us up.

However, ALT=a is a minor issue as it's just one mouse click. The big problem - getting the script to work on ANY page is working great. It saves 10 or more keystrokes every image I save - (Some images need 9 or 11 down keystrokes.)

I'm not too worried about the ALT+a box staying closed as I would have to close it anyway if I needed a few more "DOWN" key presses.

Thank you VERY MUCH for your time and patience. I can understand keystrokes syntax - it's other commands that I'm going to have trouble with. But I'll persevere, as I can see a few more uses for something like this.

Once again ... :thumbsup::D:dance::ILA3:

Link to comment
Share on other sites

" Dim $hFirefox = WinGetHandle('WinWaitActive "All sizes | oldsmobile | Flickr - Photo Sharing! - Mozilla Firefox', "")

Thats my fault bro it should've been

Dim $hFirefox = WinGetHandle("All sizes | oldsmobile | Flickr - Photo Sharing! - Mozilla Firefox", "")

I'm glad its working half way decent for you. :)

Anonymous

Edited by Decipher
Spoiler

censored.jpg

 

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