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 

[Class] Browser - open URLs in your browser
Goto page 1, 2  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
animeaime



Joined: 04 Nov 2008
Posts: 1045

PostPosted: Wed Mar 25, 2009 1:50 pm    Post subject: [Class] Browser - open URLs in your browser Reply with quote

Class Library: Browser
Version 1.0

Description
Provides functionality to interact with web browsers.

Download
Browser.zip

Requirements


Functions
Browser_constant(BrowserName)
Returns the static Browser class object (used in the other functions).

Parameters
BrowserName is one of the following (case-insensitive):
"InternetExplorer" or "IE" - for Internet Explorer
"Firefox" - for Firefox (or its portable version)
"Opera" - for Opera
"Opera@USB" for Opera@USB (a portable Opera)
"GoogleChrome" for Google Chrome (or its portable version)



Browser_openURLs(BrowserObject, UrlList, UseCurrent = false, OpenURLsIn = "new tabs"):
Opens the list of URLs in the specified browser.

Parameters
UrlList - List of URLs to open (one on each line)
For multiple URLs, you can store the URLs into a variable via a continuation section (see example below).

UseCurrent - whether to use the current tab / window or to open a new tab / window before opening the URLs.

OpenURLsIn - one of these (case-insensitive):
  • "Separate window" - opens the specified URLs each in a new tab (but in a new window)
  • "New tabs" - opens each URL in a new tab
  • "New windows" - opens each URL in a new window


Browser_exists(BrowserObject):
Wrapper function for WinExist which uses the Title RegEx value of the BrowserObject for the WinTitle.

Notes: Sets the TitleMatchMode to RegEx (required), and restores the previous setting (via A_TitleMatchMode).



Browser_isActive(BrowserObject):
Wrapper function for WinActive which uses the Title RegEx value of the BrowserObject for the WinTitle.

Notes: Sets the TitleMatchMode to RegEx (required), and restores the previous setting (via A_TitleMatchMode).



Example
Code:
;"InternetExplorer" or "IE" - for Internet Explorer
;"Firefox" - for Firefox (or its portable version)
;"Opera" - for Opera
;"Opera@USB" - for Opera@USB
;"GoogleChrome" - for Google Chrome (or its portable version)

;change the browser to the one you use
UsedBrowser := Browser_constant("firefox")

;Browser_openURLs automatically trims leading and trailing spaces and tabs
;(LTrim is used to save memory)
UrlList =
(LTrim
    http://www.yahoo.com/
    http://www.google.com/
)

if !Browser_exists(UsedBrowser)
    MsgBox, 0x1010, Browser is not open, % "Please open " . Browser_getName(UsedBrowser)
        . " so that the specified URLs can be opened."

;Opens the URLs in a separate window (ignores UseCurrent)
Browser_openURLs(UsedBrowser, UrlList, 0, "separate window")


Things to come
  • Add ability to open URLs in the default browser. Does anyone know how to get the path to the default browser?
  • Currently, Browser_openURLs waits for 1 second when opening a new window (for opening in "separate window" and "new windows"). Is there a way to detect when the new window is open?


Download Browser
_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Last edited by animeaime on Sat Apr 11, 2009 10:03 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
Roland



Joined: 08 Jun 2006
Posts: 284

PostPosted: Wed Mar 25, 2009 4:47 pm    Post subject: Re: [Class] Browser - opens URLs in your browser Reply with quote

animeaime wrote:
Does anyone know how to get the path to the default browser?


Try

Code:
RegRead, defBrowser, HKCR, HTTP\shell\open\command


(taken from one of Titan's functions).
Back to top
View user's profile Send private message
animeaime



Joined: 04 Nov 2008
Posts: 1045

PostPosted: Wed Mar 25, 2009 5:08 pm    Post subject: Reply with quote

Awesome! Do you know which OSes it works for? - I'm running Vista (32-bit) works fine.

Also, will the exe path always be the first part (surrounded in quotes)?

Which one of Titan's function? - so I can look it up for more details (and to give credit to the source). I'll of course give you credit for the suggestion.
_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Last edited by animeaime on Wed Mar 25, 2009 5:12 pm; edited 3 times in total
Back to top
View user's profile Send private message Send e-mail
Guest






PostPosted: Wed Mar 25, 2009 5:08 pm    Post subject: Re: [Class] Browser - opens URLs in your browser Reply with quote

animeaime wrote:
Is there a way to detect when the new window is open?


Each window has an id, so if you enumerate, say, all Firefox windows then you can compare if there is a window with a new id compared to the ones you know about before.
Back to top
animeaime



Joined: 04 Nov 2008
Posts: 1045

PostPosted: Wed Mar 25, 2009 5:10 pm    Post subject: Reply with quote

Awesome again! So WinGet, list?
_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.
Back to top
View user's profile Send private message Send e-mail
Guest






PostPosted: Wed Mar 25, 2009 5:28 pm    Post subject: Reply with quote

Seems appropriate.
Back to top
animeaime



Joined: 04 Nov 2008
Posts: 1045

PostPosted: Wed Mar 25, 2009 5:33 pm    Post subject: Reply with quote

Thank you both, I'll add in these features.
_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.
Back to top
View user's profile Send private message Send e-mail
Roland



Joined: 08 Jun 2006
Posts: 284

PostPosted: Fri Mar 27, 2009 1:53 pm    Post subject: Reply with quote

animeaime wrote:
Awesome! Do you know which OSes it works for? - I'm running Vista (32-bit) works fine.

Also, will the exe path always be the first part (surrounded in quotes)?

Which one of Titan's function? - so I can look it up for more details (and to give credit to the source). I'll of course give you credit for the suggestion.


I'm running XP. It used to just return the exe path for me I think, now it returns those command line args as well, I don't know why.
The function was called web() I believe - really can't tell you where to look for it though, I copied it into my own collection of functions some two years ago or so.
Back to top
View user's profile Send private message
animeaime



Joined: 04 Nov 2008
Posts: 1045

PostPosted: Sun Mar 29, 2009 2:51 am    Post subject: Reply with quote

I fixed a bug in the firefox RegEx. It will now match a firefox window that has a blank tab as the active tab.

Download the updated Browser class.
_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.
Back to top
View user's profile Send private message Send e-mail
Lexikos



Joined: 17 Oct 2006
Posts: 4820
Location: Australia

PostPosted: Sun Mar 29, 2009 3:37 am    Post subject: Reply with quote

Quote:
Is there a way to detect when the new window is open?
Shell hooks can detect window creation, activation and destruction, among other things. A shell hook should be more efficient and perhaps more effective than a loop with WinGet.
Back to top
View user's profile Send private message Visit poster's website
animeaime



Joined: 04 Nov 2008
Posts: 1045

PostPosted: Sun Mar 29, 2009 3:53 am    Post subject: Reply with quote

Lexikos wrote:
Shell hooks can detect window creation, activation and destruction, among other things. A shell hook should be more efficient and perhaps more effective than a loop with WinGet.

Wow, thanks. It looks simple (and clean).

I want to check my understanding. It looks like I would hook messages to the script. Then, use OnMessage to respond to the message.
Check for window creation (lParam = 1). If a window with a matching title was created (using the RegEx, and perhaps PID), it's the one I want. Is that it? Sounds simple enough, or am I missing something?

Edit: I should be able to use the scripts HWND, right? - no need for a GUI.
_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Last edited by animeaime on Sun Mar 29, 2009 3:58 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
Lexikos



Joined: 17 Oct 2006
Posts: 4820
Location: Australia

PostPosted: Sun Mar 29, 2009 3:56 am    Post subject: Reply with quote

It should be that simple, which is why I mentioned it. You'll probably need DetectHiddenWindows, On, though.
Back to top
View user's profile Send private message Visit poster's website
animeaime



Joined: 04 Nov 2008
Posts: 1045

PostPosted: Sun Mar 29, 2009 3:59 am    Post subject: Reply with quote

Lexikos wrote:
It should be that simple, which is why I mentioned it. You'll probably need DetectHiddenWindows, On, though.

Thanks for the heads up.


I should be able to link to the script's HWND, right? - no need for a GUI.
_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.
Back to top
View user's profile Send private message Send e-mail
Lexikos



Joined: 17 Oct 2006
Posts: 4820
Location: Australia

PostPosted: Sun Mar 29, 2009 4:14 am    Post subject: Reply with quote

Correct.
Back to top
View user's profile Send private message Visit poster's website
animeaime



Joined: 04 Nov 2008
Posts: 1045

PostPosted: Sun Mar 29, 2009 4:15 am    Post subject: Reply with quote

Awesome, thanks again.
_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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