| View previous topic :: View next topic |
| Author |
Message |
Piet Guest
|
Posted: Tue Feb 15, 2005 5:07 pm Post subject: Close Opera (safely) with Autohotkey |
|
|
Hi people,
I want to close Opera 8 (www.opera.com) using a Autohotkey script. First i tried
| Code: | | taskkill /im opera.exe |
but this doesn't work well since if there are multiple windows open, only one of them is closed. If I used it in a loop, this wouldn't work well, since I want Opera to remember all pages from this session the next time it starts up.
I also tried
| Code: | | taskkill /f /im opera.exe |
but this kills Opera without letting it save the open windows etc.
I tried
| Code: | | ControlSend, , ^q, Opera |
to send Opera the close hotkey (Ctrl+Q), but it didn't work either. (Previously, I did also SetTitleMatchMode, 2)
Has anyone any ideas how to close Opera cleanly?
Thanks (and thanks to the Autohotkey maintainer for the program!)!
Piet |
|
| Back to top |
|
 |
Piet Guest
|
Posted: Tue Feb 15, 2005 5:09 pm Post subject: |
|
|
| Opera also doesn't have any command line args to close it. |
|
| Back to top |
|
 |
polyethene
Joined: 11 Aug 2004 Posts: 5248 Location: UK
|
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 2951 Location: Minnesota
|
Posted: Tue Feb 15, 2005 6:21 pm Post subject: |
|
|
| WinClose is equivalent to pressing a program's X button in the top right. If that's not what you want it to do, though, you could see if it's a menu item and then select it using WinMenuSelectItem. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10716
|
Posted: Tue Feb 15, 2005 6:52 pm Post subject: |
|
|
Actually, WinClose isn't quite the same as the X button. The X button usually produces an SC_CLOSE message (similar to Alt-F4), while WinClose sends WM_CLOSE to the window, which is a littler harsher.
Here is the way that is closest to Alt-F4:
PostMessage, 0x112, 0xF060,,, WinTitle, WinText ; 0x112 = WM_SYSCOMMAND, 0xF060 = SC_CLOSE |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 2951 Location: Minnesota
|
Posted: Tue Feb 15, 2005 7:34 pm Post subject: |
|
|
Ah, that's right. Dang, I should know that, too, because I just researched that a little while ago for the KDE script.  |
|
| Back to top |
|
 |
piet
Joined: 15 Feb 2005 Posts: 5
|
Posted: Tue Feb 15, 2005 7:50 pm Post subject: |
|
|
Thanks for the quick replies! Unfortunately, none of your proposes worked for me
WinClose, WinKill and PostMessage with the proposed parameters only close one window if multiple browser windows are open.
WinMenuSelectItem didnt work either, as Opera seems to have non-standard menus. Although it would have been nice, I think I can also close Opera manually.
Maybe I'll try ControlSend again...
But thanks again
Piet
Last edited by piet on Tue Feb 15, 2005 8:23 pm; edited 1 time in total |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 2951 Location: Minnesota
|
Posted: Tue Feb 15, 2005 7:59 pm Post subject: |
|
|
| Have you tried a loop with IfWinExist and WinClose? If one string matches all browser windows (like " - Opera" or something), that should close them all. |
|
| Back to top |
|
 |
Guest
|
Posted: Tue Feb 15, 2005 8:22 pm Post subject: |
|
|
If I used a loop to close one window at a time, then at the next start Opera would only reopen the last closed window. Instead, if I exit Opera with Ctrl-Q (corresponds to File/Exit), the next time Opera will automatically open all the windows opened during the last session.
But when I tried ControlSend to send Ctrl-Q, it didnt work  |
|
| Back to top |
|
 |
ranomore
Joined: 06 Nov 2004 Posts: 170 Location: Salt Lake City, UT
|
Posted: Tue Feb 15, 2005 8:44 pm Post subject: |
|
|
Did you try to ControlSend to the active window, or to a control in the window?
| Code: | | ControlSend, Edit1, ^Q |
is different than
unless Edit1 is the topmost control of the window.
It seems odd to me that a key like CTRL+Q wouldn't send properly via AHK.
Did you try:
|
|
| Back to top |
|
 |
piet
Joined: 15 Feb 2005 Posts: 5
|
Posted: Tue Feb 15, 2005 10:28 pm Post subject: |
|
|
| Code: | | ControlSend, OperaWindowClass16, ^q, Opera |
made it work. Previously, I omitted the second parameter, but it seems to be needed.
Thanks for your help
Piet |
|
| Back to top |
|
 |
Watcher
Joined: 27 Dec 2004 Posts: 60
|
Posted: Thu Feb 17, 2005 1:57 am Post subject: |
|
|
| Just a thought, Opera handles tabbed windows very well... if you try it you'll never go back ). |
|
| Back to top |
|
 |
|