Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 17, 2013, 03:18 PM   #1
bluereef
macrumors member
 
Join Date: Jan 2012
Apple Script Help

Would someone be so kind as to help me with a code problem.

set weatherWindChillSpeed to COL_YELLOW & "Like: " & weatherWindChill & degrees & " Outside Right Now / Wind Speed Is: " & weatherWindSpeed & " " & speed & COL_RESET & newline & newline & COL_YELLOW & "Wind Direction From The: " & weatherWindDirection

Comes out like this:

"Like: 76 F Outside Right Now / Wind Speed Is: 12 mph

Wind Direction From The: South South East

Relative Humidity : 40% / Visibility Distance: 10 mi

 Atmospheric Pressure: 30.09 in - Rising: 2 in"

What I want to do is to indent : WIND DIRECTION FROM THE SOUTH SOUTH EAST

So It would be centered instead of having it indented to the left
bluereef is offline   0 Reply With Quote
Old Mar 17, 2013, 03:31 PM   #2
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Please post the entire code and use code tags.
__________________
Space Corps Directive 34124
kryten2 is offline   0 Reply With Quote
Old Mar 17, 2013, 03:45 PM   #3
bluereef
Thread Starter
macrumors member
 
Join Date: Jan 2012
Total Script

Code:
 white_space : {space, tab, return, (ASCII character 10), (ASCII character 13)}
on run
	set pathName to "/Users/papabear/Documents/WeatherIcon"
	set weatherFile to pathName & "/WeatherIcon.txt"
	set weatherLocation to "USFL0378"
	set tempType to "f" -- "f" for Fahrenheit and "c" for Celsius  must be lowercase
	
	set COL_RED to "\\\\x1b[37\\;01m"
	set COL_GREEN to "\\\\x1b[37\\;01m"
	set COL_YELLOW to "\\\\x1b[37\\;01m"
	set COL_RESET to "\\\\x1b[37\\;37\\;00m"
	set newline to "\\\\n"
	set degreesF to " F"
	set degreesC to " C"
	set degrees to ""
	
	if tempType is equal to "f" then
		set degrees to degreesF
	else if tempType is equal to "c" then
		set degrees to degreesC
	end if
	
	set weatherCurl to (do shell script "curl --silent 'http://xml.weather.yahoo.com/forecastrss/" & weatherLocation & "_" & tempType & ".xml' | grep  'yweather:' >" & weatherFile)
	
	--set weatherCurl to (do shell script "curl --silent 'http://weather.yahooapis.com/forecastrss?p=" & weatherLocation & "&u=f' | grep  'yweather:' >" & weatherFile)
	
	set distance to (do shell script "grep -E 'yweather:units' " & weatherFile & "| sed -e 's/.*distance=//;s/pressure=.*//' | sed 's/\"//g'") as string
	set distance to (my trim_string(distance, white_space, "both"))
	
	set pressure to (do shell script "grep -E 'yweather:units' " & weatherFile & "| sed -e 's/.*pressure=//;s/speed=.*//' | sed 's/\"//g'") as string
	set pressure to (my trim_string(pressure, white_space, "both"))
	
	set speed to (do shell script "grep -E 'yweather:units' " & weatherFile & "| sed -e 's/.*speed=//;s/\\/>.*//' | sed 's/\"//g'") as string
	set speed to (my trim_string(speed, white_space, "both"))
	
	
	set weatherRegion to (do shell script "grep -E 'yweather:location' " & weatherFile & "| sed -e 's/.*region=//;s/country=.*//' | sed 's/\"//g'") as string
	set weatherRegion to (my trim_string(weatherRegion, white_space, "both"))
	
	set weatherCountry to (do shell script "grep -E 'yweather:location' " & weatherFile & "| sed -e 's/.*country=//;s/\\/>.*//' | sed 's/\"//g'") as string
	set weatherCountry to (my trim_string(weatherCountry, white_space, "both"))
	
	
	set weatherCondition to (do shell script "grep -E 'yweather:condition' " & weatherFile & "| sed -e 's/.*text=//;s/code=.*//' | sed 's/\"//g'") as string
	set weatherCondition to (my trim_string(weatherCondition, white_space, "both"))
	
	set weatherTemp to (do shell script "grep -E 'yweather:condition' " & weatherFile & "| sed -e 's/.*temp=//;s/date=.*//' | sed 's/\"//g'") as string
	set weatherTemp to (my trim_string(weatherTemp, white_space, "both"))
	
	set weatherCondition to COL_YELLOW & weatherCondition & ", " & weatherTemp & degrees & COL_RESET
	
	set weatherWindChill to (do shell script "grep -E 'yweather:wind' " & weatherFile & "| sed -e 's/.*chill=//;s/direction=.*//' | sed 's/\"//g'") as string
	set weatherWindChill to (my trim_string(weatherWindChill, white_space, "both"))
	
	set weatherWindDirection to (do shell script "grep -E 'yweather:wind' " & weatherFile & "   | sed -e 's/.*direction=//;s/speed=.*//' | sed 's/\"//g'") as string
	set weatherWindDirection to (my trim_string(weatherWindDirection, white_space, "both"))
	set weatherWindDirection to (my windDirection(weatherWindDirection))
	
	set weatherWindSpeed to (do shell script "grep -E 'yweather:wind' " & weatherFile & "| sed -e 's/.*speed=//;s/\\/>.*//' | sed 's/\"//g'") as string
	set weatherWindSpeed to (my trim_string(weatherWindSpeed, white_space, "both"))
	
	set weatherWindChillSpeed to COL_YELLOW & "Like: " & weatherWindChill & degrees & " Outside Right Now /       Wind Speed Is: " & weatherWindSpeed & " " & speed & COL_RESET & newline & newline & COL_YELLOW & "Wind Direction From The: " & weatherWindDirection
	
	
	
	
	set weatherHumidity to (do shell script "grep -E 'yweather:atmosphere' " & weatherFile & "| sed -e 's/.*humidity=//;s/visibility=.*//' | sed 's/\"//g'") as string
	set weatherHumidity to (my trim_string(weatherHumidity, white_space, "both"))
	
	set weatherVisibilty to (do shell script "grep -E 'yweather:atmosphere' " & weatherFile & "| sed -e 's/.*visibility=//;s/pressure=.*//' | sed 's/\"//g'") as string
	set weatherVisibilty to (my trim_string(weatherVisibilty, white_space, "both"))
	
	set weatherPressure to (do shell script "grep -E 'yweather:atmosphere' " & weatherFile & "| sed -e 's/.*pressure=//;s/rising=.*//' | sed 's/\"//g'") as string
	set weatherPressure to (my trim_string(weatherPressure, white_space, "both"))
	
	set weatherRising to (do shell script "grep -E 'yweather:atmosphere' " & weatherFile & "| sed -e 's/.*rising=//;s/\\/>.*//' | sed 's/\"//g'") as string
	set weatherRising to (my trim_string(weatherRising, white_space, "both"))
	
	--set weatherAtmosphere to COL_YELLOW & "Humdity: " & weatherHumidity & "%    / Visibility: " & weatherVisibilty & " " & distance & "    /    Pressure:" & weatherPressure & " " & pressure & "    -    Rising:" & weatherRising & " " & pressure & COL_RESET
	
	set weatherAtmosphere to COL_YELLOW & "Relative Humidity  : " & weatherHumidity & "% / Visibility Distance: " & weatherVisibilty & " " & distance & COL_RESET & newline & newline & COL_YELLOW & "      Atmospheric Pressure: " & weatherPressure & " " & pressure & " - Rising: " & weatherRising & " " & pressure & COL_RESET
	
	set weatherIcon to (do shell script "grep -E 'yweather:condition' " & weatherFile & "| sed -e 's/.*code=//;s/temp=.*//' | sed 's/\"//g'") as string
	set weatherIcon to (my trim_string(weatherIcon, white_space, "both"))
	
	do shell script ("cp " & pathName & "/png/" & weatherIcon & ".png " & pathName & "/WeatherIcon.png")
	
	do shell script ("echo " & weatherWindChillSpeed & newline & newline & weatherAtmosphere)
	
end run

on trim_string(the_string, trim_chars, trim_parameter)
	set start_char to 1
	set end_char to length of the_string
	set all_chars to (characters of the_string)
	
	if trim_parameter is in {"left", "both"} then
		repeat with each_char in all_chars
			if each_char is not in trim_chars then exit repeat
			set start_char to (start_char + 1)
		end repeat
	end if
	
	if trim_parameter is in {"right", "both"} then
		set all_chars to reverse of all_chars
		repeat with each_char in all_chars
			if each_char is not in trim_chars then exit repeat
			set end_char to (end_char - 1)
		end repeat
	end if
	
	try
		return text start_char thru end_char of the_string
	on error
		return ""
	end try
end trim_string

on windDirection(theDegrees)
	
	set degrees to theDegrees as number
	
	if (degrees ≥ 0 and degrees ≤ 11.25) then
		return "North"
	end if
	if degrees > 11.25 and degrees ≤ 33.75 then
		return "North North East"
	end if
	if (degrees > 33.75 and degrees ≤ 56.25) then
		return "North East"
	end if
	if (degrees > 56.25 and degrees ≤ 78.75) then
		return "East North East"
	end if
	if (degrees > 78.75 and degrees ≤ 101.25) then
		return "East"
	end if
	if (degrees > 101.25 and degrees ≤ 123.75) then
		return "East South East"
	end if
	if (degrees > 123.75 and degrees ≤ 146.25) then
		return "South East"
	end if
	if (degrees > 146.25 and degrees ≤ 168.75) then
		return "South South East"
	end if
	if (degrees > 168.75 and degrees ≤ 191.25) then
		return "South"
	end if
	if (degrees > 191.25 and degrees ≤ 213.75) then
		return "South South West"
	end if
	if (degrees > 213.75 and degrees ≤ 236.25) then
		return "South West"
	end if
	if (degrees > 236.25 and degrees ≤ 258.75) then
		return "West South West"
	end if
	if (degrees > 258.75 and degrees ≤ 281.25) then
		return "West"
	end if
	if (degrees > 281.25 and degrees ≤ 303.75) then
		return "West North West"
	end if
	if (degrees > 303.75 and degrees ≤ 326.25) then
		return "North West"
	end if
	if (degrees > 326.25 and degrees ≤ 348.75) then
		return "North North West"
	end if
	if (degrees > 348.75 and degrees ≤ 360) then
		return "North"
	end if
	
	return ""
	
end windDirection
bluereef is offline   0 Reply With Quote
Old Mar 17, 2013, 05:08 PM   #4
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
I could be wrong but I think there's no way of text formatting a string in pure Applescript. As you also can see your ANSI color codes don't quite produce the output you thought they would. I'd look into something other than Applescript if you want to color and format strings.
__________________
Space Corps Directive 34124
kryten2 is offline   0 Reply With Quote
Old Mar 17, 2013, 05:13 PM   #5
bluereef
Thread Starter
macrumors member
 
Join Date: Jan 2012
Script

I did it before but cannot remember how I did it...
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2013-03-08 at 6.47.21 PM.png
Views:	23
Size:	98.4 KB
ID:	403064  
bluereef is offline   0 Reply With Quote
Old Mar 19, 2013, 08:42 AM   #6
bluereef
Thread Starter
macrumors member
 
Join Date: Jan 2012
519 views and no help come on guys?!!!
bluereef is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Need Help With Apple Script dididan2000 Mac Programming 3 Mar 11, 2014 05:22 PM
Apple script batch shell script prramesh Mac Programming 5 Sep 15, 2013 04:35 AM
Apple script to do the following? rhett7660 Mac Applications and Mac App Store 0 Jul 10, 2013 06:25 PM
Apple Script Solution Bigjolly Mac Programming 3 Jan 14, 2013 08:08 AM
first script/autamator script feed back zyr123 Mac Programming 1 Jul 17, 2012 11:00 AM

Forum Jump

All times are GMT -5. The time now is 08:53 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC