Results 1 to 4 of 4

Thread: Mac OS script help

  1. #1
    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...!

  2. #2
    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...!

  3. #3
    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

  4. #4
    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...!

Similar Threads

  1. Replies: 3
    Last Post: 17-08-2010, 09:06 PM
  2. Is it possible to execute Perl script within another script?
    By RasMus in forum Software Development
    Replies: 2
    Last Post: 21-07-2009, 10:57 PM
  3. Word 2008 + bibfuse: no script in script menu
    By deval4u in forum Software Development
    Replies: 5
    Last Post: 06-04-2009, 12:53 PM
  4. Replies: 2
    Last Post: 14-01-2009, 01:25 PM
  5. Startup Script or Login Script ??
    By WANNABE in forum Active Directory
    Replies: 5
    Last Post: 22-12-2006, 07:44 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,093,727.36632 seconds with 16 queries