durosity, this is the script I have running right now. Most of it is repetitive work, so it could be simplified a lot with a couple routines. I just haven't had time to revisit it. I run this as an external script file.
In my case, I didn't want a line longer than 45 characters, so it's all hard-coded to that. It splits both period1 and period2, So that I can utilize both on the control page.
- Code: Select all
using terms from application "IndigoServer"
tell application "IndigoServer"
set day1Period1Forecast to value of variable "Wunderground_Day1Period1TextForecast" as string
set day1Period2Forecast to value of variable "Wunderground_Day1Period2TextForecast" as string
if length of day1Period1Forecast is less than 46 then
set the value of variable "day1Period1Line1" to day1Period1Forecast as string
set value of variable "day1Period1Line2" to ""
set value of variable "day1Period1Line3" to ""
set value of variable "day1Period1Line4" to ""
set value of variable "day1Period1Line5" to ""
set value of variable "day1Period1Line6" to ""
end if
if ((length of day1Period1Forecast is less than 91) and (length of day1Period1Forecast is greater than 45)) then
set splitChar2 to 0
set splitChar to 45
set lastChar to "-"
repeat until lastChar is equal to " "
set lastChar to character splitChar of day1Period1Forecast
set splitChar to splitChar - 1
end repeat
if ((length of day1Period1Forecast) - (splitChar + 2)) is greater than 45 then
set splitChar2 to splitChar + 45
set lastChar2 to "-"
repeat until lastChar2 is equal to " "
set lastChar2 to character splitChar2 of day1Period1Forecast
set splitChar2 to splitChar2 - 1
end repeat
end if
set value of variable "day1Period1Line1" to (characters 1 through splitChar of day1Period1Forecast) as string
if splitChar2 is equal to 0 then
set value of variable "day1Period1Line2" to (characters (splitChar + 2) through -1 of day1Period1Forecast) as string
set value of variable "day1Period1Line3" to ""
set value of variable "day1Period1Line4" to ""
set value of variable "day1Period1Line5" to ""
set value of variable "day1Period1Line6" to ""
else
set value of variable "day1Period1Line2" to (characters (splitChar + 2) through splitChar2 of day1Period1Forecast) as string
set value of variable "day1Period1Line3" to (characters (splitChar2 + 2) through -1 of day1Period1Forecast) as string
set value of variable "day1Period1Line4" to ""
set value of variable "day1Period1Line5" to ""
set value of variable "day1Period1Line6" to ""
end if
end if
if ((length of day1Period1Forecast is greater than 90) and (length of day1Period1Forecast is less than 136)) then
set splitChar3 to 0
set splitChar to 45
set lastChar to "-"
repeat until lastChar is equal to " "
set lastChar to character splitChar of day1Period1Forecast
set splitChar to splitChar - 1
end repeat
set splitChar2 to splitChar + 45
set lastChar2 to "-"
repeat until lastChar2 is equal to " "
set lastChar2 to character splitChar2 of day1Period1Forecast
set splitChar2 to splitChar2 - 1
end repeat
if ((length of day1Period1Forecast) - (splitChar2 + 2)) is greater than 45 then
set splitChar3 to splitChar2 + 45
set lastChar3 to "-"
repeat until lastChar3 is equal to " "
set lastChar3 to character splitChar3 of day1Period1Forecast
set splitChar3 to splitChar3 - 1
end repeat
end if
set value of variable "day1Period1Line1" to (characters 1 through splitChar of day1Period1Forecast) as string
set value of variable "day1Period1Line2" to (characters (splitChar + 2) through splitChar2 of day1Period1Forecast) as string
if splitChar3 is equal to 0 then
set value of variable "day1Period1Line3" to (characters (splitChar2 + 2) through -1 of day1Period1Forecast) as string
set value of variable "day1Period1Line4" to ""
set value of variable "day1Period1Line5" to ""
set value of variable "day1Period1Line6" to ""
else
set value of variable "day1Period1Line3" to (characters (splitChar2 + 2) through splitChar3 of day1Period1Forecast) as string
set value of variable "day1Period1Line4" to (characters (splitChar3 + 2) through -1 of day1Period1Forecast) as string
set value of variable "day1Period1Line5" to ""
set value of variable "day1Period1Line6" to ""
end if
end if
if ((length of day1Period1Forecast is greater than 135) and (length of day1Period1Forecast is less than 181)) then
set splitChar4 to 0
set splitChar to 45
set lastChar to "-"
repeat until lastChar is equal to " "
set lastChar to character splitChar of day1Period1Forecast
set splitChar to splitChar - 1
end repeat
set splitChar2 to splitChar + 45
set lastChar2 to "-"
repeat until lastChar2 is equal to " "
set lastChar2 to character splitChar2 of day1Period1Forecast
set splitChar2 to splitChar2 - 1
end repeat
set splitChar3 to splitChar2 + 45
set lastChar3 to "-"
repeat until lastChar3 is equal to " "
set lastChar3 to character splitChar3 of day1Period1Forecast
set splitChar3 to splitChar3 - 1
end repeat
if ((length of day1Period1Forecast) - (splitChar3 + 2)) is greater than 45 then
set splitChar4 to splitChar3 + 45
set lastChar4 to "-"
repeat until lastChar4 is equal to " "
set lastChar4 to character splitChar4 of day1Period1Forecast
set splitChar4 to splitChar4 - 1
end repeat
end if
set value of variable "day1Period1Line1" to (characters 1 through splitChar of day1Period1Forecast) as string
set value of variable "day1Period1Line2" to (characters (splitChar + 2) through splitChar2 of day1Period1Forecast) as string
set value of variable "day1Period1Line3" to (characters (splitChar2 + 2) through splitChar3 of day1Period1Forecast) as string
if splitChar4 is equal to 0 then
set value of variable "day1Period1Line4" to (characters (splitChar3 + 2) through -1 of day1Period1Forecast) as string
set value of variable "day1Period1Line5" to ""
set value of variable "day1Period1Line6" to ""
else
set value of variable "day1Period1Line4" to (characters (splitChar3 + 2) through splitChar4 of day1Period1Forecast) as string
set value of variable "day1Period1Line5" to (characters (splitChar4 + 2) through -1 of day1Period1Forecast) as string
set value of variable "day1Period1Line6" to ""
end if
end if
if ((length of day1Period1Forecast is greater than 180) and (length of day1Period1Forecast is less than 226)) then
set splitChar5 to 0
set splitChar to 45
set lastChar to "-"
repeat until lastChar is equal to " "
set lastChar to character splitChar of day1Period1Forecast
set splitChar to splitChar - 1
end repeat
set splitChar2 to splitChar + 45
set lastChar2 to "-"
repeat until lastChar2 is equal to " "
set lastChar2 to character splitChar2 of day1Period1Forecast
set splitChar2 to splitChar2 - 1
end repeat
set splitChar3 to splitChar2 + 45
set lastChar3 to "-"
repeat until lastChar3 is equal to " "
set lastChar3 to character splitChar3 of day1Period1Forecast
set splitChar3 to splitChar3 - 1
end repeat
set splitChar4 to splitChar3 + 45
set lastChar4 to "-"
repeat until lastChar4 is equal to " "
set lastChar4 to character splitChar4 of day1Period1Forecast
set splitChar4 to splitChar4 - 1
end repeat
if ((length of day1Period1Forecast) - (splitChar4 + 2)) is greater than 45 then
set splitChar5 to splitChar4 + 45
set lastChar5 to "-"
repeat until lastChar5 is equal to " "
set lastChar5 to character splitChar5 of day1Period1Forecast
set splitChar5 to splitChar5 - 1
end repeat
end if
set value of variable "day1Period1Line1" to (characters 1 through splitChar of day1Period1Forecast) as string
set value of variable "day1Period1Line2" to (characters (splitChar + 2) through splitChar2 of day1Period1Forecast) as string
set value of variable "day1Period1Line3" to (characters (splitChar2 + 2) through splitChar3 of day1Period1Forecast) as string
set value of variable "day1Period1Line4" to (characters (splitChar3 + 2) through splitChar4 of day1Period1Forecast) as string
if splitChar5 is equal to 0 then
set value of variable "day1Period1Line5" to (characters (splitChar4 + 2) through -1 of day1Period1Forecast) as string
set value of variable "day1Period1Line6" to ""
else
set value of variable "day1Period1Line5" to (characters (splitChar4 + 2) through splitChar5 of day1Period1Forecast) as string
set value of variable "day1Period1Line6" to (characters (splitChar5 + 2) through -1 of day1Period1Forecast) as string
end if
end if
if length of day1Period1Forecast is greater than 225 then
set value of variable "day1Period1Line1" to (characters 1 through 45 of day1Period1Forecast) as string
set value of variable "day1Period1Line2" to (characters 46 through 90 of day1Period1Forecast) as string
set value of variable "day1Period1Line3" to (characters 91 through 135 of day1Period1Forecast) as string
set value of variable "day1Period1Line4" to (characters 136 through 180 of day1Period1Forecast) as string
set value of variable "day1Period1Line5" to (characters 181 through 225 of day1Period1Forecast) as string
set value of variable "day1Period1Line6" to (characters 226 through -1 of day1Period1Forecast) as string
end if
--These are for period 2
if length of day1Period2Forecast is less than 46 then
set the value of variable "day1Period2Line1" to day1Period2Forecast as string
set value of variable "day1Period2Line2" to ""
set value of variable "day1Period2Line3" to ""
set value of variable "day1Period2Line4" to ""
set value of variable "day1Period2Line5" to ""
set value of variable "day1Period2Line6" to ""
end if
if ((length of day1Period2Forecast is less than 91) and (length of day1Period2Forecast is greater than 45)) then
set splitChar2 to 0
set splitChar to 45
set lastChar to "-"
repeat until lastChar is equal to " "
set lastChar to character splitChar of day1Period2Forecast
set splitChar to splitChar - 1
end repeat
if ((length of day1Period2Forecast) - (splitChar + 2)) is greater than 45 then
set splitChar2 to splitChar + 45
set lastChar2 to "-"
repeat until lastChar2 is equal to " "
set lastChar2 to character splitChar2 of day1Period2Forecast
set splitChar2 to splitChar2 - 1
end repeat
end if
set value of variable "day1Period2Line1" to (characters 1 through splitChar of day1Period2Forecast) as string
if splitChar2 is equal to 0 then
set value of variable "day1Period2Line2" to (characters (splitChar + 2) through -1 of day1Period2Forecast) as string
set value of variable "day1Period2Line3" to ""
set value of variable "day1Period2Line4" to ""
set value of variable "day1Period2Line5" to ""
set value of variable "day1Period2Line6" to ""
else
set value of variable "day1Period2Line2" to (characters (splitChar + 2) through splitChar2 of day1Period2Forecast) as string
set value of variable "day1Period2Line3" to (characters (splitChar2 + 2) through -1 of day1Period2Forecast) as string
set value of variable "day1Period2Line4" to ""
set value of variable "day1Period2Line5" to ""
set value of variable "day1Period2Line6" to ""
end if
end if
if ((length of day1Period2Forecast is greater than 90) and (length of day1Period2Forecast is less than 136)) then
set splitChar3 to 0
set splitChar to 45
set lastChar to "-"
repeat until lastChar is equal to " "
set lastChar to character splitChar of day1Period2Forecast
set splitChar to splitChar - 1
end repeat
set splitChar2 to splitChar + 45
set lastChar2 to "-"
repeat until lastChar2 is equal to " "
set lastChar2 to character splitChar2 of day1Period2Forecast
set splitChar2 to splitChar2 - 1
end repeat
if ((length of day1Period2Forecast) - (splitChar2 + 2)) is greater than 45 then
set splitChar3 to splitChar2 + 45
set lastChar3 to "-"
repeat until lastChar3 is equal to " "
set lastChar3 to character splitChar3 of day1Period2Forecast
set splitChar3 to splitChar3 - 1
end repeat
end if
set value of variable "day1Period2Line1" to (characters 1 through splitChar of day1Period2Forecast) as string
set value of variable "day1Period2Line2" to (characters (splitChar + 2) through splitChar2 of day1Period2Forecast) as string
if splitChar3 is equal to 0 then
set value of variable "day1Period2Line3" to (characters (splitChar2 + 2) through -1 of day1Period2Forecast) as string
set value of variable "day1Period2Line4" to ""
set value of variable "day1Period2Line5" to ""
set value of variable "day1Period2Line6" to ""
else
set value of variable "day1Period2Line3" to (characters (splitChar2 + 2) through splitChar3 of day1Period2Forecast) as string
set value of variable "day1Period2Line4" to (characters (splitChar3 + 2) through -1 of day1Period2Forecast) as string
set value of variable "day1Period2Line5" to ""
set value of variable "day1Period2Line6" to ""
end if
end if
if ((length of day1Period2Forecast is greater than 135) and (length of day1Period2Forecast is less than 181)) then
set splitChar4 to 0
set splitChar to 45
set lastChar to "-"
repeat until ((lastChar is equal to " ") or (lastChar is equal to "."))
set lastChar to character splitChar of day1Period2Forecast
set splitChar to splitChar - 1
end repeat
set splitChar2 to splitChar + 45
set lastChar2 to "-"
repeat until lastChar2 is equal to " "
set lastChar2 to character splitChar2 of day1Period2Forecast
set splitChar2 to splitChar2 - 1
end repeat
set splitChar3 to splitChar2 + 45
set lastChar3 to "-"
repeat until lastChar3 is equal to " "
set lastChar3 to character splitChar3 of day1Period2Forecast
set splitChar3 to splitChar3 - 1
end repeat
if ((length of day1Period2Forecast) - (splitChar3 + 2)) is greater than 45 then
set splitChar4 to splitChar3 + 45
set lastChar4 to "-"
repeat until lastChar4 is equal to " "
set lastChar4 to character splitChar4 of day1Period2Forecast
set splitChar4 to splitChar4 - 1
end repeat
end if
set value of variable "day1Period2Line1" to (characters 1 through splitChar of day1Period2Forecast) as string
set value of variable "day1Period2Line2" to (characters (splitChar + 2) through splitChar2 of day1Period2Forecast) as string
set value of variable "day1Period2Line3" to (characters (splitChar2 + 2) through splitChar3 of day1Period2Forecast) as string
if splitChar4 is equal to 0 then
set value of variable "day1Period2Line4" to (characters (splitChar3 + 2) through -1 of day1Period2Forecast) as string
set value of variable "day1Period2Line5" to ""
set value of variable "day1Period2Line6" to ""
else
set value of variable "day1Period2Line4" to (characters (splitChar3 + 2) through splitChar4 of day1Period2Forecast) as string
set value of variable "day1Period2Line5" to (characters (splitChar4 + 2) through -1 of day1Period2Forecast) as string
set value of variable "day1Period2Line6" to ""
end if
end if
if ((length of day1Period2Forecast is greater than 180) and (length of day1Period2Forecast is less than 226)) then
set splitChar5 to 0
set splitChar to 45
set lastChar to "-"
repeat until lastChar is equal to " "
set lastChar to character splitChar of day1Period2Forecast
set splitChar to splitChar - 1
end repeat
set splitChar2 to splitChar + 45
set lastChar2 to "-"
repeat until lastChar2 is equal to " "
set lastChar2 to character splitChar2 of day1Period2Forecast
set splitChar2 to splitChar2 - 1
end repeat
set splitChar3 to splitChar2 + 45
set lastChar3 to "-"
repeat until lastChar3 is equal to " "
set lastChar3 to character splitChar3 of day1Period2Forecast
set splitChar3 to splitChar3 - 1
end repeat
set splitChar4 to splitChar3 + 45
set lastChar4 to "-"
repeat until lastChar4 is equal to " "
set lastChar4 to character splitChar4 of day1Period2Forecast
set splitChar4 to splitChar4 - 1
end repeat
if ((length of day1Period2Forecast) - (splitChar4 + 2)) is greater than 45 then
set splitChar5 to splitChar4 + 45
set lastChar5 to "-"
repeat until lastChar5 is equal to " "
set lastChar5 to character splitChar6 of day1Period2Forecast
set splitChar5 to splitChar5 - 1
end repeat
end if
set value of variable "day1Period2Line1" to (characters 1 through splitChar of day1Period2Forecast) as string
set value of variable "day1Period2Line2" to (characters (splitChar + 2) through splitChar2 of day1Period2Forecast) as string
set value of variable "day1Period2Line3" to (characters (splitChar2 + 2) through splitChar3 of day1Period2Forecast) as string
set value of variable "day1Period2Line4" to (characters (splitChar3 + 2) through splitChar4 of day1Period2Forecast) as string
if splitChar5 is equal to 0 then
set value of variable "day1Period2Line5" to (characters (splitChar4 + 2) through -1 of day1Period2Forecast) as string
set value of variable "day1Period2Line6" to ""
else
set value of variable "day1Period2Line5" to (characters (splitChar4 + 2) through splitChar5 of day1Period2Forecast) as string
set value of variable "day1Period2Line6" to (characters (splitChar5 + 2) through -1 of day1Period2Forecast) as string
end if
end if
if length of day1Period2Forecast is greater than 225 then
set splitChar6 to 0
set splitChar to 45
set lastChar to "-"
repeat until lastChar is equal to " "
set lastChar to character splitChar of day1Period2Forecast
set splitChar to splitChar - 1
end repeat
set splitChar2 to splitChar + 45
set lastChar2 to "-"
repeat until lastChar2 is equal to " "
set lastChar2 to character splitChar2 of day1Period2Forecast
set splitChar2 to splitChar2 - 1
end repeat
set splitChar3 to splitChar2 + 45
set lastChar3 to "-"
repeat until lastChar3 is equal to " "
set lastChar3 to character splitChar3 of day1Period2Forecast
set splitChar3 to splitChar3 - 1
end repeat
set splitChar4 to splitChar3 + 45
set lastChar4 to "-"
repeat until lastChar4 is equal to " "
set lastChar4 to character splitChar4 of day1Period2Forecast
set splitChar4 to splitChar4 - 1
end repeat
set splitChar5 to splitChar4 + 45
set lastChar5 to "-"
repeat until lastChar5 is equal to " "
set lastChar5 to character splitChar4 of day1Period2Forecast
set splitChar5 to splitChar5 - 1
end repeat
if ((length of day1Period2Forecast) - (splitChar5 + 2)) is greater than 45 then
set splitChar6 to splitChar5 + 45
set lastChar6 to "-"
repeat until lastChar6 is equal to " "
set lastChar6 to character splitChar6 of day1Period2Forecast
set splitChar6 to splitChar6 - 1
end repeat
end if
set value of variable "day1Period2Line1" to (characters 1 through splitChar of day1Period2Forecast) as string
set value of variable "day1Period2Line2" to (characters (splitChar + 2) through splitChar2 of day1Period2Forecast) as string
set value of variable "day1Period2Line3" to (characters (splitChar2 + 2) through splitChar3 of day1Period2Forecast) as string
set value of variable "day1Period2Line4" to (characters (splitChar3 + 2) through splitChar4 of day1Period2Forecast) as string
set value of variable "day1Period2Line5" to (characters (splitChar4 + 2) through splitChar5 of day1Period2Forecast) as string
if splitChar6 is equal to 0 then
set value of variable "day1Period2Line6" to (characters (splitChar5 + 2) through -1 of day1Period2Forecast) as string
else
set value of variable "day1Period2Line6" to (characters (splitChar5 + 2) through splitChar6 of day1Period2Forecast) as string
end if
end if
end tell
end using terms from