AutoHotkey Community

It is currently May 26th, 2012, 4:25 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: March 25th, 2009, 1:50 pm 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
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 April 11th, 2009, 10:03 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 25th, 2009, 4:47 pm 
Offline

Joined: June 8th, 2006, 9:38 pm
Posts: 307
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).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 25th, 2009, 5:08 pm 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
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 March 25th, 2009, 5:12 pm, edited 3 times in total.

Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 25th, 2009, 5:08 pm 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 25th, 2009, 5:10 pm 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 25th, 2009, 5:28 pm 
Seems appropriate.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 25th, 2009, 5:33 pm 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 27th, 2009, 1:53 pm 
Offline

Joined: June 8th, 2006, 9:38 pm
Posts: 307
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 29th, 2009, 2:51 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 29th, 2009, 3:37 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 29th, 2009, 3:53 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
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 March 29th, 2009, 3:58 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 29th, 2009, 3:56 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
It should be that simple, which is why I mentioned it. You'll probably need DetectHiddenWindows, On, though.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 29th, 2009, 3:59 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 29th, 2009, 4:14 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
Correct.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 29th, 2009, 4:15 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
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.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group