Re: Opening a specified URL in a specified browser (was: AppleScript-Users Digest, Vol 3, Issue 654)
Re: Opening a specified URL in a specified browser (was: AppleScript-Users Digest, Vol 3, Issue 654)
- Subject: Re: Opening a specified URL in a specified browser (was: AppleScript-Users Digest, Vol 3, Issue 654)
- From: kai <email@hidden>
- Date: Mon, 1 Jan 2007 19:06:18 +0000
On 29 Dec 2006, at 22:17, Craig Hoyt wrote:
I'm doing this (Safari misspelled intentionally to show problem):
try
tell application "Saffari"
activate
end tell
end try
This will produce a dialog asking the user to 'Find' the
application 'Saffari'. Is this now a Finder issue? Is there any way
to suppress this dialog? try doesn't seem to work here. Am I doing
this correctly? Is there a more appropriate way to do this such as
actually checking for the existence of the application first? The
problem reverts to the fact that a human enters the application
name - thus I must allow for typos. I just want it to fail silently.
The dialog resulting from specifying an unknown application is more
an attempt to identify the intended target than an actual error,
Craig. So, while a try statement can trap a runtime error, it won't
suppress this particular kind of dialog. To avoid it, we really need
to determine that an application exists before addressing it.
While you appear to have now come up with a solution, I'll throw this
into the hat anyway (some of which reiterates previous comments).
Manual entry of an existing file/application/process name is probably
not the best way to specify a target; choosing from a defined list is
generally preferable. As already suggested, this can be achieved by
using the 'choose application' or 'choose file' commands from
Standard Additions. However, I suppose there's still a risk that the
user might select a target other than a browser. One way to focus on
specific applications might be to identify their names from a list of
bundle identifiers, which allows for different names/versions. Some
examples of these methods are included below.
If still pursuing your original aim of opening a URL in a user-
specified browser, bear in mind that some statements (including the
'set URL of document 1' construct for Safari, discussed earlier) may
be application-specific. Such an approach could therefore necessitate
a series of if/then statements to accommodate various individual
expressions for achieving a similar result in other apps (assuming,
of course, that they're armed with a suitable equivalent).
For a more general form, consider 'open location' from Standard
Additions. Within certain tell statements, this may decompile as some
other term (such as 'Get URL', in a number of Mozilla-based
browsers). However, the underlying raw event code («event GURLGURL»)
is exactly the same, and 'open location' should therefore work when
initially compiling - or if the target application is not directly
and explicitly named (as in the following examples).
Any line abutting the margin may need to be rejoined with the
previous one:
--------------
set target_url to "http://www.google.com/" (* or whatever *)
set target_browser to choose application with prompt "Choose a
browser:"
tell target_browser to activate (open location target_url)
--------------
set target_url to "http://www.google.com/" (* or whatever *)
set target_browser to (choose file of type
"com.apple.application-bundle" with prompt "Choose a browser:"
default location (path to applications folder) without invisibles) as
Unicode text
tell application target_browser to activate (open location
target_url)
--------------
to |choose browser|()
set l to {"com.freeverse.bumpercar", "org.mozilla.camino",
"org.mozilla.firefox", "org.mozilla.flock", "de.icab.iCab",
"com.microsoft.explorer", "com.app4mac.KidsBrowser",
"net.habilis.lynxlet", "org.mozilla.mozilla", "com.netscape.mozilla",
"com.omnigroup.OmniWeb5", "com.operasoftware.Opera",
"com.apple.Safari", "org.mozilla.seamonkey", "net.hmdt-web.Shiira",
"com.sunrisebrowser.SunriseBrowser"}
tell application "Finder" to repeat with i in l
try
set i's contents to application file id i's displayed name
end try
end repeat
tell (choose from list l's every Unicode text with prompt
"Choose a browser:")
if it is false then error number -128
beginning
end tell
end |choose browser|
set target_url to "http://www.google.com/" (* or whatever *)
set target_browser to |choose browser|()
tell application target_browser to activate (open location
target_url)
--------------
---
kai
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/mailman//archives/applescript-users
This email sent to email@hidden