Jump to content

AutoIt Script Help


Recommended Posts

Dear Sir or Ma'am,

Perhaps you can help with this script?

I want it to open WordWeb whether or not it is already in the system tray. I use Responding Heads to run AutoIt Scripts. If you can convert this to VB for RH to use without AutoIt, that would be even better.

Opt("WinTitleMatchMode",2)

If WinActive("WordWeb") Then ~~~(this probably won't work because its not active if in the system tray?)

Send("^%W") ~~~(cntl+alt+W)

Else run "C:\Program Files\WordWeb\wweb32.exe" ~~~(error here. Run command???)

Sleep(10000) ~~~(time it takes to load???)

Send("^%W")

End If

Thank you so much,

Amerigo

Link to comment
Share on other sites


You have a tray executable and a no tray executable and also window states to consider. I chose the cover all known scenarios.


; path to webword directory
$ww_path = @ProgramFilesDir & '\WordWeb'
; WordWeb NoTray executable
$exe_notray = 'wwnotray.exe'
; WordWeb Tray executable
$exe_tray = 'wweb32.exe'
; main window title
$title = '[CLASS:TTHeDi]'

Select
Case WinActive($title)
; nothing to do
Exit
Case ProcessExists($exe_notray) And Not WinActive($title)
; restore and activate the window
WinSetState($title, '', @SW_RESTORE)
WinActivate($title)
Case ProcessExists($exe_tray) And Not WinActive($title)
; run tray exe to activate the window
_RunWordWeb($exe_tray)
Case Else
; no process running so choose $exe_notray or $exe_tray to run
_RunWordWeb($exe_tray)
EndSelect

Exit

Func _RunWordWeb($file)
; check to ensure the file to run is available, else return if not
If Not FileExists($ww_path & '\' & $file) Or $file = '' Then
Return SetError(1)
EndIf
Switch $file
Case $exe_notray
; run no tray exe to show window
Run('"' & $ww_path & '\' & $exe_notray & '"')
; wait for the window and then activate it
WinWait($title, '', 5)
WinActivate($title)
Case $exe_tray
; run instances of tray exe until the window is active
Do
Run('"' & $ww_path & '\' & $exe_tray & '"')
If Not ProcessExists($exe_tray) Then
; something is incorrect so return from this function
Return SetError(2)
Else
Sleep(250)
; activate the window
WinActivate($title)
EndIf
Until WinActive($title)
EndSwitch
EndFunc

Starting a 2nd instance of the tray process seems to bring up the window so I chose that idea rather then the hotkey idea.

Note that the keyword "Else" likes it's own line in AutoIt3 except for "Case Else" as to your code error. Also "End If" needs to be "EndIf".

:)

Link to comment
Share on other sites

Thanks to both of you.

MHz, I like the way you think. Covering all the bases.

However, there is a glitch somewhere. I tried it with WordWeb completely off, and it worked, and worked, and worked.....

It seems to have gotten caught in a loop where it tries to keep opening WordWeb.

Link to comment
Share on other sites

It seems to have gotten caught in a loop where it tries to keep opening WordWeb.

Sorry. My results are different for some reason.

This will use the Ctrl+Alt+w hotkey


; path to webword directory
$ww_path = @ProgramFilesDir & '\WordWeb'
; WordWeb NoTray executable
$exe_notray = 'wwnotray.exe'
; WordWeb Tray executable
$exe_tray = 'wweb32.exe'
; main window title
$title = '[CLASS:TTHeDi]'

Select
Case WinActive($title)
; nothing to do
Exit
Case ProcessExists($exe_notray) And Not WinActive($title)
; restore and activate the window
WinSetState($title, '', @SW_RESTORE)
WinActivate($title)
Case ProcessExists($exe_tray) And Not WinActive($title)
; run tray exe to activate the window
_RunWordWeb($exe_tray)
Case Else
; no process running so choose $exe_notray or $exe_tray to run
_RunWordWeb($exe_tray)
EndSelect

Exit

Func _RunWordWeb($file)
; check to ensure the file to run is available, else return if not
If Not FileExists($ww_path & '\' & $file) Or $file = '' Then
Return SetError(1)
EndIf
Switch $file
Case $exe_notray
; run no tray exe to show window
Run('"' & $ww_path & '\' & $exe_notray & '"')
If Not @error Then
; wait for the window and then activate it
WinWait($title, '', 5)
WinActivate($title)
EndIf
Case $exe_tray
; run tray exe
Run('"' & $ww_path & '\' & $exe_tray & '"')
If Not @error Then
; wait for hidden tray icon window
WinWait('WordWeb Tray Icon', '', 5)
Sleep(500)
; if the window is not active, then use the hotkey
If Not WinActive($title) Then
WinActivate($title)
Send('^!w')
EndIf
EndIf
EndSwitch
Sleep(500)
; another attempt to activate the window if needed
If Not WinActive($title) Then
WinActivate($title)
EndIf
EndFunc

If you wish, you can run the no tray executable instead by changing the parameter of _RunWordWeb() in the Case Else part which shows a window which behave like a normal window.

before:

	Case Else
; no process running so choose $exe_notray or $exe_tray to run
_RunWordWeb($exe_tray)
EndSelect

after:

	Case Else
; no process running so choose $exe_notray or $exe_tray to run
_RunWordWeb($exe_notray)
EndSelect

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
  • Recently Browsing   0 members

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