Skip to content

Textexpander: Snippet to get tomorrow’s weather forecast via AppleScript

This content will be shown before all post

Just downloaded TextExpander yesterday and coming up with new ways to make it useful.  I travel often and always wanting to know what the weather is going to be like in my next destination, so I made the snippet "getweather" that is the AppleScript code below to prompt me for what zip code I will be in, then load that location's weather forecast for tomorrow in Google Chrome.

Fun!

tell application "TextExpander" to activate
display dialog "What zip code?" default answer ""
set zip to (text returned of result)

tell application "Google Chrome"
	activate
	set theUrl to "http://www.weather.com/weather/tomorrow/" & zip

	if (count every window) = 0 then
		make new window
	end if

	set found to false
	set theTabIndex to -1
	repeat with theWindow in every window
		set theTabIndex to 0
		repeat with theTab in every tab of theWindow
			set theTabIndex to theTabIndex + 1
			if theTab's URL = theUrl then
				set found to true
				exit
			end if
		end repeat

		if found then
			exit repeat
		end if
	end repeat

	if found then
		tell theTab to reload
		set theWindow's active tab index to theTabIndex
		set index of theWindow to 1
	else
		tell window 1 to make new tab with properties {URL:theUrl}
	end if
end tell
This content will be shown after all post