| View previous topic :: View next topic |
| Author |
Message |
animeaime
Joined: 04 Nov 2008 Posts: 1045
|
Posted: Wed Mar 25, 2009 1:50 pm Post subject: [Class] Browser - open URLs in your browser |
|
|
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 |
|
 |
Roland
Joined: 08 Jun 2006 Posts: 284
|
Posted: Wed Mar 25, 2009 4:47 pm Post subject: Re: [Class] Browser - opens URLs in your browser |
|
|
| 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 |
|
 |
animeaime
Joined: 04 Nov 2008 Posts: 1045
|
Posted: Wed Mar 25, 2009 5:08 pm Post subject: |
|
|
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 |
|
 |
Guest
|
Posted: Wed Mar 25, 2009 5:08 pm Post subject: Re: [Class] Browser - opens URLs in your browser |
|
|
| 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
|
Posted: Wed Mar 25, 2009 5:10 pm Post subject: |
|
|
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 |
|
 |
Guest
|
Posted: Wed Mar 25, 2009 5:28 pm Post subject: |
|
|
| Seems appropriate. |
|
| Back to top |
|
 |
animeaime
Joined: 04 Nov 2008 Posts: 1045
|
Posted: Wed Mar 25, 2009 5:33 pm Post subject: |
|
|
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 |
|
 |
Roland
Joined: 08 Jun 2006 Posts: 284
|
Posted: Fri Mar 27, 2009 1:53 pm Post subject: |
|
|
| 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 |
|
 |
animeaime
Joined: 04 Nov 2008 Posts: 1045
|
Posted: Sun Mar 29, 2009 2:51 am Post subject: |
|
|
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 |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 4820 Location: Australia
|
Posted: Sun Mar 29, 2009 3:37 am Post subject: |
|
|
| 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 |
|
 |
animeaime
Joined: 04 Nov 2008 Posts: 1045
|
Posted: Sun Mar 29, 2009 3:53 am Post subject: |
|
|
| 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 |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 4820 Location: Australia
|
Posted: Sun Mar 29, 2009 3:56 am Post subject: |
|
|
| It should be that simple, which is why I mentioned it. You'll probably need DetectHiddenWindows, On, though. |
|
| Back to top |
|
 |
animeaime
Joined: 04 Nov 2008 Posts: 1045
|
Posted: Sun Mar 29, 2009 3:59 am Post subject: |
|
|
| 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 |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 4820 Location: Australia
|
Posted: Sun Mar 29, 2009 4:14 am Post subject: |
|
|
| Correct. |
|
| Back to top |
|
 |
animeaime
Joined: 04 Nov 2008 Posts: 1045
|
Posted: Sun Mar 29, 2009 4:15 am Post subject: |
|
|
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 |
|
 |
|