Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

tobylane

macrumors newbie
Original poster
Aug 28, 2009
8
0
It's meant to pass a url between browsers. It errors on the line where the <<< is, with the error of 'Expected "then", etc, but found identifier. What can I do? Plus, as I'm new to this any general ideas I lack in?
Code:
tell application "System Events"
	delay 1
	--Change Opera and Safari for your two browsers.
	set b1 to "Opera"
	set b2 to "Safari"
	say b1
	set myApp to name of first application process whose frontmost is true
	if myApp is "b1" then
		say yes
		tell application b1
			set myInfo to GetWindowInfo of window 1
			set myURL to item 1 of myInfo
		end tell
	else if myApp is "Safari then
		tell application b2
			set myURL to URL of document 1
		end tell
	else
	say else
	return
	end if
	if myApp is "b1" then               <<<<<
		tell application b2
			OpenURL myURL
		end tell
	else if myApp is "b2" then
		tell application b1
			make new document with properties {URL:theURL}
		end tell
	else
		say "test2"
		return
	end if
end tell
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Two problems I see initially

Code:
else if myApp is "Safari then

Missing a quote.

Code:
say else

Not sure what that's supposed to be, but "else" is undefined.
 

tobylane

macrumors newbie
Original poster
Aug 28, 2009
8
0
Of course. I didn't expect it to support multiline names or not to say if there's a quote mismatch.

'System Events got an error: can't get application "Safari"' from line ' set myURL to URL of document 1'

Also (when that if part isn't run), Opera is apparently triggered by OpenURL Var, but that or OpenURL "address" isn't accepted by the editor, 'Expected end of line but found identifier' highlighting the variable.
 

mysterytramp

macrumors 65816
Jul 17, 2008
1,334
4
Maryland
Of course. I didn't expect it to support multiline names or not to say if there's a quote mismatch.

This is a source of a lot of frustration with AppleScript -- not detecting quote failures. Unlike lots of languages, a string in AppleScript can be most anything, including several paragraphs. So it becomes a tradeoff. You gain the greater flexibility on strings, but you also have to know that when you see some errors, it means you quoted improperly.

Speaking of which:

Code:
	if myApp is "b1" then
		[ ... ]
	if myApp is "b1" then               <<<<<
		[ ... ]
	else if myApp is "b2" then

I don't believe "b1" and "b2" need to be in quotes here. You have created vars b1 and b2 to represent the names of your browsers. Putting them in quotes means you're telling AS that you want those two strings, "b1" and "b2" and not the values they represent.

mt
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.