AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Close Opera (safely) with Autohotkey

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Piet
Guest





PostPosted: Tue Feb 15, 2005 5:07 pm    Post subject: Close Opera (safely) with Autohotkey Reply with quote

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





PostPosted: Tue Feb 15, 2005 5:09 pm    Post subject: Reply with quote

Opera also doesn't have any command line args to close it.
Back to top
polyethene



Joined: 11 Aug 2004
Posts: 5248
Location: UK

PostPosted: Tue Feb 15, 2005 5:37 pm    Post subject: Reply with quote

You could use PostMessage or WinKill
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jonny



Joined: 13 Nov 2004
Posts: 2951
Location: Minnesota

PostPosted: Tue Feb 15, 2005 6:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10716

PostPosted: Tue Feb 15, 2005 6:52 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
jonny



Joined: 13 Nov 2004
Posts: 2951
Location: Minnesota

PostPosted: Tue Feb 15, 2005 7:34 pm    Post subject: Reply with quote

Ah, that's right. Dang, I should know that, too, because I just researched that a little while ago for the KDE script. Confused
Back to top
View user's profile Send private message
piet



Joined: 15 Feb 2005
Posts: 5

PostPosted: Tue Feb 15, 2005 7:50 pm    Post subject: Reply with quote

Thanks for the quick replies! Unfortunately, none of your proposes worked for me Sad
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
View user's profile Send private message
jonny



Joined: 13 Nov 2004
Posts: 2951
Location: Minnesota

PostPosted: Tue Feb 15, 2005 7:59 pm    Post subject: Reply with quote

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
View user's profile Send private message
Guest






PostPosted: Tue Feb 15, 2005 8:22 pm    Post subject: Reply with quote

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 Sad
Back to top
ranomore



Joined: 06 Nov 2004
Posts: 170
Location: Salt Lake City, UT

PostPosted: Tue Feb 15, 2005 8:44 pm    Post subject: Reply with quote

Did you try to ControlSend to the active window, or to a control in the window?
Code:
ControlSend, Edit1, ^Q

is different than
Code:
ControlSend, , ^Q

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:
Code:
Send, ^Q
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
piet



Joined: 15 Feb 2005
Posts: 5

PostPosted: Tue Feb 15, 2005 10:28 pm    Post subject: Reply with quote

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
View user's profile Send private message
Watcher



Joined: 27 Dec 2004
Posts: 60

PostPosted: Thu Feb 17, 2005 1:57 am    Post subject: Reply with quote

Just a thought, Opera handles tabbed windows very well... if you try it you'll never go back ).
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group