Requesting optimization of g4fancontrol script

Ok so as you may or may not know, G4FanControl lets you override the sensors in the laptop. Only problem is it doesn’t retain the settings after reboot. (Even though it says it does.) So I set out to write a script to change the settings every time I restarted. I used UI Browser and I couldn’t for the life of me get it to let me do backround scripting. (Noted as comments in the script.) So if you have any optimizations to pull this script away from messy GUI scripting, I would be greatly appreciative.

delay 5
activate application "G4FanControl"
tell application "System Events"
	tell process "G4FanControl"
		repeat until exists window "Password:"
			delay 0.5
		end repeat
		--set value of text field 1 of window "Password:" to "test"
		keystroke "[admin password here]"
		delay 0.5
		keystroke return
		--click the button "OK" of group 2 of window "Password:"
		delay 0.5
		repeat until exists window "Info"
			delay 0.5
		end repeat
		keystroke return
		repeat until exists window "G4FanControl 0.5"
			delay 0.5
		end repeat
		--set value of slider 2 of group 2 of window "G4FanControl 0.5" to 40
		(*keystroke tab
		keystroke tab
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		keystroke tab
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		keystroke tab
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123
		key code 123*)
	end tell
	tell application "Extra Suites"
		ES move mouse {859, 543}
		ES click mouse
		ES move mouse {791, 543}
		ES click mouse
		
		ES move mouse {855, 581}
		ES click mouse
		ES move mouse {800, 581}
		ES click mouse
		
		ES move mouse {892, 619}
		ES click mouse
		ES move mouse {809, 619}
		ES click mouse
	end tell
	delay 0.5
	tell application "System Events"
		keystroke "q" using command down
	end tell
end tell

Hi Sk8.4.Life,

Just a thought: Andrea Fabrizi also offers a free command line version of its application, which you can easily compile on your Mac. Then you could write an AppleScript that executes this command line tool with the required arguments (your custom fan settings) every time you reboot (startup item). This way you could eliminate GUI scripting.