Jump to content

Problem with 'Case' code working only once


Recommended Posts

This code uses a button press to copy highlighted text from Firefox and store it in a $, then copy the URL and store it in a $, switch to another app, assemble the parts and paste it. Sometimes it works many time in a row, sometimes only once. But it always works at least the first time. I've changed several parts of it, added sleep's all over, used different functions, etc., but i can't seem to pin this one.

Case $Msg = $Button_HeadlineFf
    WinActivate('[REGEXPTITLE:(?-i:Mozilla Firefox); CLASS:MozillaUIWindowClass]')
    WinWaitActive('[REGEXPTITLE:(?-i:Mozilla Firefox); CLASS:MozillaUIWindowClass]')
    Send("^c")          ; copy headline
    $Get_ClipHl = ClipGet(); store headline
    Send("^l")          ; select URL
    Send("^c")          ; copy URL
    $Get_ClipUrl = ClipGet(); store URL
    WinActivate('[REGEXPTITLE:(?-i:KompoZer); CLASS:MozillaWindowClass]')
    WinWaitActive('[REGEXPTITLE:(?-i:KompoZer); CLASS:MozillaWindowClass]')
    Send("!i")      ; open "insert" menu
    Send("h")       ; select "HTML"
    WinWaitActive('[TITLE:Insert HTML]')
    Clipput('<h1><a class="headline-linked" href="' & $Get_ClipUrl & '">' & $Get_ClipHl & '</a></h1>')
    Sleep(5)
    Send("^v")      ; paste HTML
    Send("!i")      ; apply changes and close "insert HTML" window
    WinWaitActive('[REGEXPTITLE:(?-i:KompoZer); CLASS:MozillaWindowClass]')
    Send("^s")      ; save document
    WinActivate('[REGEXPTITLE:(?-i:Mozilla Firefox); CLASS:MozillaUIWindowClass]')
Link to comment
Share on other sites

If you want to do this with Firefox, then it should be done from INSIDE Firefox with XUL.

If you want to do it with AutoIt, you will be better off with Internet Explorer and the IE.au3 UDF functions.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

You're talking to someone who detests IE, so the latter isn't an option :)

I realize AutoIt is probably not the ideal solution, but i'm clinging to it like a dog humping my leg because i'm just learning how to do this stuff and i find it very intuitive and well documented with a feature set that's small enough for me to wrap my head around while still being capable of far more that i am... at this point.

So if anyone can point out any blatant problems with the code, i'd be very appreciative. I'll be happy to post all of it if necessary.

Link to comment
Share on other sites

Try adding Sleep() before each Send(). The problem I came across before is that you have to compensate on varrying latency. WinWaitActive() "should" do all the waiting, but if you notice, the title of the page could already be on your window title even before the page actually have loaded, which in this case your code will fire up even when the page is not yet ready.

I'm not really sure if this is the problem you're experiencing, but if the code works as it should and sometimes it's not, this might be the one causing it. Add Sleep() before Send() and see what happens.

[font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version

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