I'm trying to write something that will open several web sites

–I’m trying to open several web pages
http://www.marketwatch.com/investing/stock/GGG
http://www.marketwatch.com/investing/stock/CHRW
http://www.marketwatch.com/investing/stock/BPOP
http://www.marketwatch.com/investing/stock/DCT
…and can’t seem to get very far–

set list_1 to {“GGG”, “CHRW”, “BPOP”, “DCT”}
set list_2 to {“http://www.marketwatch.com/investing/stock/”}
set list_3 to {item 1 of list_2} & {item 1 of list_1}

get list_3 as string

tell application “Safari”

activate

open location "get list_3 as string"

end tell

I don’t understand your question but this is the shortest you can get

open location "http://www.marketwatch.com/investing/stock/GGG"
open location "http://www.marketwatch.com/investing/stock/CHRW"
open location "http://www.marketwatch.com/investing/stock/BPOP"
open location "http://www.marketwatch.com/investing/stock/DCT"

All URLs will be opened with the standard browser. and open location isn’t an safari command so you don’t need the safari’s tell block.

Ultimately, I would like to use a display dialog command to input stock symbols (e.g. “GGG”, “CHRW”, “BPOP”, “DCT”) and combine that data with the URL, or others, in order to open the pages.

In other words, I want to write this so I can input the stock symbols and stem URL.

-- If marketwatch has a webservice/api you shouldn't use the following line.
-- Instead you should fetch the latest stock names from marketwatch. 
-- Even better if marketwatch supports xmlrpc or soap services.
set stockNames to {"GGG", "CHRW", "BPOP", "DCT"}

set baseURL to "http:www.marketwatch.com"

set selectedStock to choose from list stockNames with title "Select Stock" empty selection allowed no multiple selections allowed no

open location (baseURL & "/investing/stock/" & selectedStock as string)

As an alternate, if you wanted to open more than one of the pages at a time, you could either use a repeat loop to make up and use the full URL to each item or (as it turns out) use the “open” shell script, which accepts Unix-like multi-URLs. eg.

“open [color=black]http://www.marketwatch.co/investing/stock/{GGG,CHRW,DCT}[/color]

-- If marketwatch has a webservice/api you shouldn't use the following line.
-- Instead you should fetch the latest stock names from marketwatch. 
-- Even better if marketwatch supports xmlrpc or soap services.
set stockNames to {"GGG", "CHRW", "BPOP", "DCT"}

set baseURL to "http://www.marketwatch.com"

set selectedStock to (choose from list stockNames with title "Select Stock" with multiple selections allowed without empty selection allowed)
if (selectedStock is false) then error number -128

if ((count selectedStock) > 1) then
	set astid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to ","
	set selectedStock to "{" & selectedStock & "}"
	set AppleScript's text item delimiters to astid
end if

do shell script "open " & baseURL & "/investing/stock/" & selectedStock

Actually, you can shorten it further (more lines, but almost 100 fewer characters).

set a to "http://www.marketwatch.com/investing/stock/"
open location a & "GGG"
open location a & "CHRW"
open location a & "BPOP"
open location a & "DCT"

Kudos!

:smiley:

Do you mean something like this?

set a to "http://www.marketwatch.com/investing/stock/"
set b to text returned of (display dialog "Stock Symbol:" default answer "" with title "Stock Checker")
open location a & b

:slight_smile:

Look at my post and nigel’s variant with multiple selections :slight_smile:

So no kudos… kudos for nigel :slight_smile:

Hi, pneshati.

The number of characters in ApplesScript source code is completely irrelevant, apart from legibility considerations. From the point of view of what the code actually does, DJ’s script is “shorter” than yours. It simply takes the provided URLs and feeds them to the ‘open location’ command. Yours has to build the URLs from the bits first, which means it does more work and uses more memory to accomodate both the complete URLs and the bits.

Your script’s perfectly OK, but DJ’s is more efficient and (to my eyes) more immediately legible.