Open URL with specific app using AppleScript

I’ve created a stripped-down browser using Fluid (http://fluidapp.com/) and would like to use it to open the URL’s in the following script so that they open more quickly and in one, centralised tool (I’d prefer not to have them open in Safari or Firefox).

Here is the first part of the script:

-- ------------------------------------------------------------
-- Dialog box into which search queries are entered
-- ------------------------------------------------------------
set search to text returned of (display dialog "Enter Search Query - Joint Terms with \"+\":" default answer "" buttons {"Search", "Cancel"} default button "Search")

-- ------------------------------------------------------------
-- Sets the clipboard to the value of 'search'
-- ------------------------------------------------------------
set the clipboard to search

-- ------------------------------------------------------------
-- Sets language/tool selection options
-- ------------------------------------------------------------
set lang to {"German", "Dutch", "Google Tools", "Reference", "Currency Converter"}

-- ------------------------------------------------------------
-- Allows for language/tool selection
-- ------------------------------------------------------------
set langSelect to (choose from list lang with prompt "Make Selection:" without multiple selections allowed) as text

-- ------------------------------------------------------------
-- Changes encoding from UTF-8 to predicated ISO-8859-1
-- ------------------------------------------------------------
set searchEncoded to do shell script "/bin/echo -n " & quoted form of search & " | iconv -f utf8 -t iso-8859-1 | php -r '$handle = fopen (\"php://stdin\",\"r\"); $line = fgets($handle);echo urlencode($line);'"

-- ------------------------------------------------------------
-- Begin of if-statements for search engines choices
-- ------------------------------------------------------------
if langSelect is "German" then
	set sites to {"Linguee", "Glosbe", "Beolingus", "Leo", "DictData", "Woerterbuch.info", "Langenscheidt", "Uni Leipzig", "Redensarten", "Google", "Google Images", "Wiki.de", "DWDS", "Lisa", "SAP.com", "Pons", "Dict.cc", "Eur-Lex", "Europarl", "UBS Banking", "MS Language Portal", "WIPO", "IATE", "All Sites"}
	set chosen to (choose from list sites with prompt "Make Selection:" without multiple selections allowed) as text
	if chosen is "Linguee" then
		open location "http://www.linguee.com/english-german/search?sourceoverride=none&source=auto&query=" & searchEncoded
	else if chosen is "Glosbe" then
		open location "http://en.glosbe.com/de/en/" & searchEncoded
	else if chosen is "Beolingus" then
		open location "http://dict.tu-chemnitz.de/dings.cgi?lang=en&service=deen&opterrors=0&optpro=0&query=" & searchEncoded & "&iservice=&comment=&email="

etc. etc. etc.

I’ve tried using things like:

Tell “MyBrowser.app” to open “www.linguee.com” etc.

tell application “MyBrowser.app”
OpenURL “http://www.macosxhints.com/
end tell

do shell script “open -a MyBrowser.app http://linguee.com

Nothing like this has worked, however.

Can anyone suggest a way to get this to work? The above suggestions seem to have worked for others as I’ve found these on various different sites, but for some reason they have not worked so far for me.

Thanks,

bowjest

try


set identifier to "my.browser.bundleIdentifier"
tell application id identifier to open location "[url=http://www.myURL.com]www.myURL.com[/url]"

If you don’t know them, use:

set i to bundle identifier of (get info for (choose file))

Thanks, Stefan and Adam.

I’m afraid I don’t understand how to implement the syntax here. I tried to work both suggestions in a number of ways, but couldn’t get them to work.

Is the bundle identifier something I would find under Preferences or similar?

Using the code snippet below, can you tell me how to insert your suggestions?


-- ------------------------------------------------------------
-- Begin of if-statements for search engines choices
-- ------------------------------------------------------------
if langSelect is "German" then
   set sites to {"Linguee", "Glosbe", "Beolingus", "Leo", "DictData", "Woerterbuch.info", "Langenscheidt", "Uni Leipzig", "Redensarten", "Google", "Google Images", "Wiki.de", "DWDS", "Lisa", "SAP.com", "Pons", "Dict.cc", "Eur-Lex", "Europarl", "UBS Banking", "MS Language Portal", "WIPO", "IATE", "All Sites"}
   set chosen to (choose from list sites with prompt "Make Selection:" without multiple selections allowed) as text
   if chosen is "Linguee" then
       open location "http://www.linguee.com/english-german/search?sourceoverride=none&source=auto&query=" & searchEncoded

etc. etc. etc.

Sorry to ask that it be spelt out so explicitly, but I’m not really that programming savvy.

Thanks,

bowjest

Assuming you want to build in to your script a specific browser for German, use the script I posted (click on the link that says “Open this scriptlet in your editor”), run that, choose the browser you want and the script will return the bundle identifier. Copy that ID and paste it into Stefan’s script in place of the phrase “my.browser.bundleIdentifier”.

Then, instead of:

open location "http://www.linguee.com/english-german/search?sourceoverride=none&source=auto&query=" & searchEncoded

as is in your script, use

set identifier to "my.browser.bundleIdentifier" -- with the appropriate bundle id here
tell application id identifier to open location "http://www.linguee.com/english-german/search?sourceoverride=none&source=auto&query=" & searchEncoded"

Thanks, Adam.

That sort of worked: by that I mean, if I use the following:

set identifier to "com.fluidapp.FluidApp.Linguee"
if langSelect is "German" then
	set sites to {"Linguee", "Glosbe", "Beolingus", "Leo", "DictData", "Woerterbuch.info", "Langenscheidt", "Uni Leipzig", "Redensarten", "Google", "Google Images", "Wiki.de", "DWDS", "Lisa", "SAP.com", "Pons", "Dict.cc", "Eur-Lex", "Europarl", "UBS Banking", "MS Language Portal", "WIPO", "IATE", "All Sites"}
	set chosen to (choose from list sites with prompt "Make Selection:" without multiple selections allowed) as text
	if chosen is "Linguee" then
		tell application id identifier to open location "http://www.linguee.com/english-german/search?sourceoverride=none&source=auto&query=" & searchEncoded
etc. etc. etc.

It opens my search term in a new tab in my “Linguee” browser.

However, for any subsequent items that I choose, for example:


set identifier to "com.fluidapp.FluidApp.Linguee"
if langSelect is "German" then
	set sites to {"Linguee", "Glosbe", "Beolingus", "Leo", "DictData", "Woerterbuch.info", "Langenscheidt", "Uni Leipzig", "Redensarten", "Google", "Google Images", "Wiki.de", "DWDS", "Lisa", "SAP.com", "Pons", "Dict.cc", "Eur-Lex", "Europarl", "UBS Banking", "MS Language Portal", "WIPO", "IATE", "All Sites"}
	set chosen to (choose from list sites with prompt "Make Selection:" without multiple selections allowed) as text
	if chosen is "Linguee" then
		tell application id identifier to open location "http://www.linguee.com/english-german/search?sourceoverride=none&source=auto&query=" & searchEncoded
	else if chosen is "Glosbe" then
		tell application id identifier to open location "http://en.glosbe.com/de/en/" & searchEncoded
etc. etc. etc.

These are just opened in my default browser, Firefox.

Thanks,

bowjest