Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 27-03-2009
Member
 
Join Date: Jan 2009
Posts: 91
Mac OS script help

Hey guys!
I want to learn scripting for mac os... Can anyone guide me? Can we control hardware parts with scripting? Can someone provide me sample script that changes and controls harware settings... would be greatful...! Thanks in advance...!
Reply With Quote
  #2  
Old 27-03-2009
Member
 
Join Date: Jan 2009
Posts: 1,738
Re: Mac OS script help

The default shell on Mac OS X is the "Bourne-again" shell, or bash. You may configure Terminal.app to use any of the available shells (or any other command shell of your choosing). To configure Terminal.app to use a different shell:
  • Start Terminal.app
  • Choose Terminal > Preferences...
  • Select the Execute this command radio button.
  • In the text field, enter the full path to the shell command you wish to execute.

All shell are located under /bin/
All the best...!

I am not under scripting so this is what i'm aware of...! All the best...!
Reply With Quote
  #3  
Old 27-03-2009
Member
 
Join Date: Mar 2009
Posts: 599
Re: Mac OS script help

Hi there...!
Even i'm not into scriptting, but here is what i found, a sample code for controlling fan speed based on bourne-again shell for mac os :

Code:
#!/bin/bash

appleSMCPath=/sys/devices/platform/applesmc.768
			# Path to applesmc (Seems static)

minTemp=30		# Lowest temperature
maxOnlineTemp=57	# Highest temperature when online
maxOfflineTemp=60	# Highest temperature when offline

fanMinSpeed=2000	# Lowest fan-speed
fanMaxSpeed=6000	# Highest fan-speed

tempCalc=highest	# Temperature calculation ("highest" uses highest temperature, "average" takes the average
sensorsUsed=6		# How many sensors to use
debug=onChange		# Set to onLoop for every loop, onChange on state-changes, or false for off
manFanControl=false	# Set to true if you want to define direct output, instead of fan minimum speeds

debug() # Prints text with a timestamp, when $debug
{
	[[ $debug == onChange ]] && [[ $stateChange == true ]] && echo "$(date "+%d/%m %H:%M:%S"): $@"
	[[ $debug == onLoop ]] && echo "$(date "+%d/%m %H:%M:%S"): $@"
}

initSetup() # Initialize
{
	fans=0
	for i in $appleSMCPath/fan*_output # Count fans
	do
		((fans++))
	done

	if [[ $manFanControl == true ]]
	then
		for i in $appleSMCPath/fan*_manual
		do
			echo 1 > $i
		done
		fanEnd="_output"
	else
		for i in $appleSMCPath/fan*_manual
		do
			echo 0 > $i
		done
		fanEnd="_min"
	fi

	debug "Fans: $fans $([[ $manFanControl == true ]] && echo ', Manually controlled')"
	debug "  Min fan-speed: $fanMinSpeed"
	debug "  Max fan-speed: $fanMaxSpeed"

	sensors=0
	for i in $appleSMCPath/temp*_input # Count temperature sensors
	do
		((sensors++))
	done

	debug "Sensors: $sensors"
	debug "  Limited by user to $sensorsUsed"

	(cat /proc/acpi/battery/BAT0/state | grep "yes" > /dev/null) && laptop=true ||*online=true
	(cat /proc/acpi/ac_adapter/ADP1/state | grep on-line > /dev/null) && online=true || online=false

	debug "Laptop: $laptop"
	debug "   ACPI-State: $([[ $online == true ]] && echo online || echo offline)"
	
}

setFans() # Adjust fan-speeds
{
	counter=0
	until [[ $counter == $fans ]]
	do
		((counter++))
		echo $1 > /sys/devices/platform/applesmc.768/fan${counter}${fanEnd}
	done
}

update() # Update temperatures and ACPI state
{

	counter=1
	until [[ $counter == $sensors ]]
	do
		tempVar=$(cat $appleSMCPath/temp${counter}_input)
		((tempSensor[$counter]=tempVar/1000))
		((counter++))
	done

	if [[ $tempCalc == "highest" ]]
	then
		counter=0
		temp=0
		until [[ $counter == $sensorsUsed ]] || [[ $counter == $sensors ]]
		do
			((counter++))
			[[ ${tempSensor[$counter]} > $temp ]] && temp=${tempSensor[$counter]}
		done
		[[ $oldTemp != $temp ]] && stateChange=true && oldTemp=$temp
	else
		counter=0
		temp=0
		until [[ $counter == $sensorsUsed ]] || [[ $counter == $sensors ]]
		do
			((counter++))
			let "temp = ${tempSensor[$counter]} + $temp"
		done
		((temp=temp/(counter-1)))
		[[ $oldTemp != $temp ]] && stateChange=true && oldTemp=$temp
	fi

	if [[ $laptop == true ]]
	then
		(cat /proc/acpi/ac_adapter/ADP1/state | grep on-line > /dev/null) && online=true || online=false

		if [[ $oldOnline != $online ]]
		then
			[[ $online == true ]] && maxTemp=$maxOnlineTemp || maxTemp=$maxOfflineTemp
			((ratio=(fanMaxSpeed-fanMinSpeed)/(maxTemp-minTemp)))
			oldOnline=$online
			stateChange=true
		fi
	fi
}

stateChange=true
initSetup

while : # Lets loop
do
	update
	if [[ $stateChange == true ]]
	then
		((speed=((temp-minTemp)*ratio)+fanMinSpeed))
		(( $speed >= $fanMaxSpeed )) && speed=$fanMaxSpeed				# Don't try to set fan-speed over $fanMaxSpeed
		(( $speed <= $fanMinSpeed )) && speed=$fanMinSpeed				# Don't try to set fan-speed under $fanMinSpeed
		setFans $speed
	fi
	debug "Temperature: $temp, Fan-speed: $speed, ACPI-State: $([[ $online == true ]] && echo online || echo offline)"
	stateChange=false
	sleep 5
done
Reply With Quote
  #4  
Old 27-03-2009
Member
 
Join Date: Jan 2009
Posts: 74
Re: Mac OS script help

Hey...!
This is what i found "The Unix shell is the main scripting environment of every Linux, Mac OS X and Unix system, whether a rescued laptop or a million-dollar mainframe. " So the bottom line is if you know unix scripting you know scripting for all the unix based OS...! All the best...!
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Mac OS script help"
Thread Thread Starter Forum Replies Last Post
Dumping logon name and logon script values to a text file - blank logon script field Phil McNeill Windows Server Help 3 17-08-2010 09:06 PM
Is it possible to execute Perl script within another script? RasMus Software Development 2 21-07-2009 10:57 PM
Word 2008 + bibfuse: no script in script menu deval4u Software Development 5 06-04-2009 12:53 PM
Problem with script in order to open another script in an extra window Samsher Software Development 2 14-01-2009 01:25 PM
Startup Script or Login Script ?? WANNABE Active Directory 5 22-12-2006 07:44 PM


All times are GMT +5.5. The time now is 04:52 AM.