Can't Expand Options in AppleScript

I have put together the following script to easily access a number of search sites. I would like to expand this to include two more tools of the same type, but when I add onto the existing tool, it fails with the error:

“Expected end but found else”.

Here is the current script:

set search to text returned of (display dialog "Enter Search Query:" default answer "" buttons {"Search", "Cancel"} default button "Search")
set lang to {"German", "Dutch"}
set langSelect to (choose from list lang with prompt "Make Language Selection:" without multiple selections allowed) as text
if langSelect is "German" then
	set sites to {"Linguee", "Google", "Wiki.de", "SAP.com", "Pons", "Dict.cc", "Euro-Lex", "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=" & search
	else if chosen is "Google" then
		open location "http://translate.google.com/?hl=en&eotf=0&sl=de&q=" & search
	else
		if chosen is "Wiki.de" then
			open location "http://de.wikipedia.org/wiki/" & search
		else
			if chosen is "SAP.com" then
				open location "http://help.sap.com/saphelp_glossary/de/index.htm"
			else
				if chosen is "Pons" then
					open location "http://mobile.pons.eu/dict/search/mobile-results/?l=deen&q=" & search
				else
					if chosen is "Dict.cc" then
						open location "http://www.dict.cc/?s=" & search
					else
						if chosen is "Euro-Lex" then
							open location "http://eur-lex.europa.eu/Result.do?arg0=" & search & "&arg1=" & search & "&arg2=&titre=titreettexte&chlang=de&RechType=RECH_mot&Submit=Suche"
						else
							if chosen is "UBS Banking" then
								open location "http://www.ubs.com/3/g?lo=t&qt=" & search & "&utf=€"
							else
								if chosen is "MS Language Portal" then
									open location "http://www.microsoft.com/Language/en-US/Search.aspx"
								else
									if chosen is "WIPO" then
										open location "http://www.wipo.int/classifications/nivilo/nice/index.htm?lang=DE#"
									else
										if chosen is "IATE" then
											open location "http://iate.europa.eu/iatediff/SearchByQueryLoad.do?method=load"
										else
											if chosen is "All Sites" then
												open location "http://www.linguee.com/english-german/search?sourceoverride=none&source=auto&query=" & search
												open location "http://translate.google.com/?hl=en&eotf=0&sl=de&q=" & search
												open location "http://de.wikipedia.org/wiki/" & search
												open location "http://help.sap.com/saphelp_glossary/de/index.htm"
												open location "http://mobile.pons.eu/dict/search/mobile-results/?l=deen&q=" & search
												open location "http://www.dict.cc/?s=" & search
												open location "http://eur-lex.europa.eu/Result.do?arg0=" & search & "&arg1=" & search & "&arg2=&titre=titreettexte&chlang=de&RechType=RECH_mot&Submit=Suche"
												open location "http://www.ubs.com/3/g?lo=t&qt=" & search & "&utf=€"
												open location "http://www.microsoft.com/Language/en-US/Search.aspx"
												open location "http://www.wipo.int/classifications/nivilo/nice/index.htm?lang=DE#"
												open location "http://iate.europa.eu/iatediff/SearchByQueryLoad.do?method=load"
											end if
										end if
									end if
								end if
							end if
						end if
					end if
				end if
			end if
		end if
	end if
else
	if langSelect is "Dutch" then
		set sites to {"MWB", "Google", "Wiki.nl", "van Dale", "Woordenboek.eu", "Dict.cc", "LookWayUp", "BabLa", "Vertalen.nu", "Euro-Lex", "IATE", "MS Language Portal", "All Sites"}
		set chosen to (choose from list sites with prompt "Make Selection:" without multiple selections allowed) as text
		if chosen is "MWB" then
			open location "http://www.mijnwoordenboek.nl/vertalen.php?woord=" & search
		else
			if chosen is "Google" then
				#open location "http://translate.google.com/#nl|en|" & search
				open location "http://translate.google.com/?hl=en&eotf=0&sl=nl&q=" & search
			else
				if chosen is "Wiki.nl" then
					open location "http://nl.wikipedia.org/wiki/" & search
				else
					if chosen is "van Dale" then
						open location "http://www.vandale.nl/vandale/zoekService.do?selectedDictionary=nn&selectedDictionaryName=Nederlands&searchQuery=" & search
					else
						if chosen is "Woordenboek.eu" then
							open location "http://www.online-languages.info/_ud2/ud2.php?l1=dutch&disa=1&rad=exact&w=" & search & "&searchword=" & search & "&nllang=Engels"
						else
							if chosen is "Dict.cc" then
								open location "http://ennl.dict.cc/?s=" & search
							else
								if chosen is "LookWayUp" then
									open location "http://lookwayup.com/lwu.exe/lwu/toEng?s=d&w=" & search & "&slang=Nld"
								else
									if chosen is "BabLa" then
										open location "http://nl.bab.la/woordenboek/nederlands-engels/" & search
									else
										if chosen is "Vertalen.nu" then
											open location "http://www.vertalen.nu/vertaal?vertaal=" & search & "&van=nl&naar=eng"
										else
											if chosen is "Euro-Lex" then
												open location "http://eur-lex.europa.eu/Result.do?arg0=" & search & "&arg1=" & search & "&arg2=&titre=titreettexte&chlang=nl&RechType=RECH_mot&Submit=Zoeken"
											else
												if chosen is "IATE" then
													open location "http://iate.europa.eu/iatediff/SearchByQueryLoad.do?method=load"
												else
													if chosen is "MS Language Portal" then
														open location "http://www.microsoft.com/Language/en-US/Search.aspx"
													else
														if chosen is "All Sites" then
															open location "http://www.mijnwoordenboek.nl/vertalen.php?woord=" & search
															open location "http://translate.google.com/?hl=en&eotf=0&sl=nl&q=" & search
															open location "http://nl.wikipedia.org/wiki/" & search
															open location "http://www.vandale.nl/vandale/zoekService.do?selectedDictionary=nn&selectedDictionaryName=Nederlands&searchQuery=" & search
															open location "http://www.online-languages.info/_ud2/ud2.php?l1=dutch&disa=1&rad=exact&w=" & search & "&searchword=" & search & "&nllang=Engels"
															open location "http://ennl.dict.cc/?s=" & search
															open location "http://lookwayup.com/lwu.exe/lwu/toEng?s=d&w=" & search & "&slang=Nld"
															open location "http://nl.bab.la/woordenboek/nederlands-engels/" & search
															open location "http://www.vertalen.nu/vertaal?vertaal=" & search & "&van=nl&naar=eng"
															open location "http://eur-lex.europa.eu/Result.do?arg0=" & search & "&arg1=" & search & "&arg2=&titre=titreettexte&chlang=nl&RechType=RECH_mot&Submit=Zoeken"
															open location "http://iate.europa.eu/iatediff/SearchByQueryLoad.do?method=load"
															open location "http://www.microsoft.com/Language/en-US/Search.aspx"
														end if
													end if
												end if
											end if
										end if
									end if
								end if
							end if
						end if
					end if
				end if
			end if
		end if
	end if
end if

I simply want to add a new section just like the previous two, but for some reason it just won’t accept the addition of new options:

else
	if langSelect is "Google Tools" then
set sites to {"Books", "Images", "Blogs", "Finance", "News", "Products", "Trends", "All Sites"}
set chosen to (choose from list sites with prompt "Make Selection:" without multiple selections allowed) as text
if chosen is "Books" then
	open location "http://www.google.co.uk/search?tbm=bks&tbo=1&q=" & search
else
	if chosen is "Images" then
		open location "http://images.google.co.uk/search?tbm=isch&hl=en&source=hp&biw=1440&bih=723&q=" & search & "&gbv=2&oq=" & search & "&aq=f&aqi=g10&aql=&gs_sm=e&gs_upl=1760l3034l0l4125l6l6l0l0l0l0l183l767l1.5l6l0"
	else
		if chosen is "Blogs" then
			open location "http://www.google.co.uk/search?tbm=blg&hl=en&source=hp&biw=&bih=&q=" & search & "&btnG=Search"
		else
			if chosen is "Finance" then
				open location "http://www.google.co.uk/finance?q=" & search
			else
				if chosen is "News" then
					open location "http://www.google.co.uk/search?aq=f&hl=en&gl=uk&tbm=nws&btnmeta_news_search=1&q=" & search
				else
					if chosen is "Products" then
						open location "http://www.google.co.uk/search?q=" & search & "&hl=en&tbm=shop&aq=f&oq=&aq=f"
					else
						if chosen is "Trends" then
							open location "http://www.google.co.uk/trends?q=" & search
						else
							if chosen is "All Sites" then
								open location "http://www.google.co.uk/search?tbm=bks&tbo=1&q=" & search
								open location "http://images.google.co.uk/search?tbm=isch&hl=en&source=hp&biw=1440&bih=723&q=" & search & "&gbv=2&oq=" & search & "&aq=f&aqi=g10&aql=&gs_sm=e&gs_upl=1760l3034l0l4125l6l6l0l0l0l0l183l767l1.5l6l0"
								open location "http://www.google.co.uk/search?tbm=blg&hl=en&source=hp&biw=&bih=&q=" & search & "&btnG=Search"
								open location "http://www.google.co.uk/finance?q=" & search
								open location "http://www.google.co.uk/search?aq=f&hl=en&gl=uk&tbm=nws&btnmeta_news_search=1&q=" & search
								open location "http://www.google.co.uk/search?q=" & search & "&hl=en&tbm=shop&aq=f&oq=&aq=f"
								open location "http://www.google.co.uk/trends?q=" & search
							end if
						end if
					end if
				end if
			end if
		end if
	end if
end if

I’ve checked that all my “if” and “end if” statements match up, but just can’t get it to accept a new “else” after the final “end if” above.

Can anyone please help?

Thanks,

Bowjest

Hi,

you should structure the if - else if conditions this way


	if chosen is "Linguee" then
		open location "http://www.linguee.com/english-german/search?sourceoverride=none&source=auto&query=" & search
	else if chosen is "Google" then
		open location "http://translate.google.com/?hl=en&eotf=0&sl=de&q=" & search
	else if chosen is "Wiki.de" then
		open location "http://de.wikipedia.org/wiki/" & search
.
	end if

this makes the script better readable (and expandable)

Hi Stefan,

Thanks for that piece of advice. I’m learning by doing, so appreciate the pointer.

You’re right - once I did that I was able to delete tons of instances of “end if” that were apparently superfluous and get the script working like I wanted.

Strangely, it seems that AppleScript doesn’t count the total numbers of "if"s and "end if"s, but rather the number of lines they are spread across (or at least it seems that way to me).

All the best,

Bowjest