Saturday, July 4, 2020

#1 2002-04-19 11:40:49 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

scripting default browser/open location

I want to be able to open several internet addresses in separate browser windows--independent of the browser.
I know there is the standard addition "open location" command, but that doesn't allow you to tell the browser to open in a new window.
Is there a work around? I could, if necessary, have separate tell blocks for each of the major browsers, but then how can I get the default browser set in the Internet Pref pane (in OS X)?
Thanks.


One mans trash is another mans treasure

Offline

 

#2 2002-04-19 12:42:19 am

Eelco Houwink
Member
Registered: 2002-11-20
Posts: 317

Re: scripting default browser/open location

In Internet Explorer, the syntax to open an URL into a new window is:

Applescript:

Tell application "Internet Explorer" to OpenURL "[url=http://www.macfixit.com]www.macfixit.com[/url]" toWindow 0

You may repeat that with all URL's you need to open.
In Netscape it may be slightly different (consult its dictionary in Script Editor)
Eelco Houwink


Eelco Houwink

Offline

 

#3 2002-04-19 12:56:16 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: scripting default browser/open location

Eelco:
I can get the syntax for each browser... In fact it is virtually the same for all browsers (other than omniweb, which is slightly different.). What I can't determine at this point is how to get the default browser in OS X via AppleScript.
FYI and everyone else's, this is what I have so far:

Applescript:

set URL1 to "[url]http://www.versiontracker.com[/url]"
set URL2 to "[url]http://www.hotmail.com[/url]"
--need a way to get the name and/or file id of the default browser!!!
display dialog "choose browser. 1=IE; 2=OW; 3=Opera; 4=iCab; 5=chimera; 6=netscape" default answer "1"
set browser to (text returned of the result) as number
if browser = 1 then
set bc to "MSIE" else if browser = 2 then
set bc to "OWEB" else if browser = 3 then
set bc to "OPRA" else if browser = 4 then
set bc to "iCAB" else if browser = 5 then
--note chimera does not yet support applescript
-- set bc to "çHIM" else if browser = 6 then
set bc to "MOSS"
end if
try
tell application "Finder" to set myBrowser to (name of application file id bc) as string
on error
set myBrowser to "Internet Explorer"
end try
tell application myBrowser
activate
using terms from application "Internet Explorer"
if myBrowser contains "OmniWeb" then
OpenURL URL1
OpenURL URL2
--OmniWeb does not support "toWindow 0" but seems to open new URLs in new windows anyway
else
OpenURL URL1 toWindow 0
OpenURL URL2 toWindow 0
end if
end using terms from
end tell


One mans trash is another mans treasure


Filed under: Finder

Offline

 

#4 2002-04-22 11:35:15 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: scripting default browser/open location

how can I get the default browser set in the Internet Pref pane (in OS X)?
: Thanks.


One mans trash is another mans treasure

Offline

 

#5 2002-04-22 12:49:40 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: scripting default browser/open location

i am not sure about osx - but for os9 you can get the default browser by simply using this...

Applescript:

open location "[url]http://www.cnn.com/[/url]"

hope this helps...


One mans trash is another mans treasure

Offline

 

#6 2002-04-22 03:03:07 am

Rob
Member
From:: Ohio, USA
Registered: 2002-11-20
Posts: 1886

Re: scripting default browser/open location

This doesn't really "get" the default browser. it "uses" the default browser. I think the goal is to find out which browser is set as the default.

Rob

Offline

 

#7 2002-04-22 03:59:49 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: scripting default browser/open location

Very true. Also:

Applescript:

<P style="white-space:nowrap;font:normal 10px/13px Geneva">«event GURLBROW»

will launch the default browser (w/o opening a URL), but you'd then have to list the active processes with the Finder and pick out the application's name/path/id.

This was presented as a solution a long time ago in this forum: Use the raw event shown above to launch the user's default browser. Script the Finder to wait a moment or two (and allow the application to launch and come to front), and then get the name/path/id of the frontmost application.

I think it would fail if the user clicks on another application (desktop, window of another app, etc.) while the Finder is waiting to make sure the browser application has had time to launch.


One mans trash is another mans treasure

Offline

 

#8 2002-04-23 11:37:43 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: scripting default browser/open location

I guess you 'll have to read out the file
DefaultHelperApps.plist that resides in:
Internet.prefPane/Contents/Resources/English.lproj
that resides in:
/System/Library/PreferencePanes
Eelco Houwink


One mans trash is another mans treasure

Offline

 

#9 2002-04-23 07:04:25 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: scripting default browser/open location

Now that you've split these openURL cmds out for each browser, why not use a generic open command first, then wait a few seconds, then get the front application, and then address the next openURL commands to that app.

Applescript:

tell application "Finder" to open location "[url]http://www.cnn.com/[/url]"
delay 2
tell application "Finder" to set fm to name of (processes) whose frontmost is true
if fm = etc. ( your script )

Success,
Eelco Houwink


One mans trash is another mans treasure


Filed under: Finder

Offline

 

#10 2002-04-24 10:52:48 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: scripting default browser/open location

inelegant, but that helps. Thanks. Do you know of a preferred way to get the "web" key with some kind of event? Or do I have to read in the file and search for :

Applescript:

web = (
{
DisplayName = "Internet Explorer";
Info = { BundleIdentifier = "com.microsoft.explorer"; };
IsDefaultHandler = YES;
}

or something? hmmm....


One mans trash is another mans treasure

Offline

 

#11 2002-04-24 11:00:45 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: scripting default browser/open location

Sounds good. But I want a generic sub-routine. To do that technique, I'd have to be able to open a random web page first, which would not be very good design. besides, it would defeat the original reason I didn't want to use "open location": it won't open a location in a new browser window (for most browsers).

The other problem with getting the info in "/System/Library/PreferencePanes/Internet.prefPane/Contents/Resources/English.lproj/DefaultHelperApps.plist" is that it depends on an english localization.
now i'd have to find out what language was being used first.
there must be a better way.


One mans trash is another mans treasure

Offline

 

#12 2002-04-24 11:11:37 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: scripting default browser/open location

I can't even figure out to refer to that file in apple script.
this doens't work

Applescript:

tell application "Finder"
set thefile to file "System:Library:PreferencePanes:Internet.prefPane:Contents:Resources:English.lproj:DefaultHelperApps.plist" of startup disk --as alias
open for access thefile
set thestring to read thefile using delimiter {"web = (", "}"}
close access thefile
end tell
set result to thestring

how do you refer to a unix path without naming the volume in apple script?


One mans trash is another mans treasure


Filed under: Finder

Offline

 

#13 2002-04-25 05:54:22 am

Krioni
Member
From:: New York, NY
Registered: 2002-11-20
Posts: 245
Website

Re: scripting default browser/open location

You'll have to change the line that reads the file delimited, since it didn't work for me, but to open and have access to the file, try this:

Applescript:

tell application "Finder"
set startupDiskName to (startup disk as string)
end tell

try
set theFileHandle to open for access file (startupDiskName & "System:Library:PreferencePanes:Internet.prefPane:Contents:Resources:English.lproj:DefaultHelperApps.plist")
set webString to read theFileHandle using delimiter {"web = (", "}"}
close access theFileHandle
return webString
on error errMsg number errNum
try
close access theFileHandle
end try
display dialog errMsg & ": " & errNum
end try


Filed under: Finder

Offline

 

#14 2002-04-25 07:27:41 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: scripting default browser/open location

Thanks.  But this is Crazy!  I just noticed that the file to which we are referring here doesn't even contain my defaults..  If I go to system prefs, my default e-mail and newsreader clients appear in the pop up menu as expected.  However, if I open that file, it does not even mention either client.  (By coincidence only perhaps I'm using Explorer as my web browser.)

Very odd.

there's got to be a way to do this.


One mans trash is another mans treasure

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)