Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

eyoungren

macrumors Nehalem
Original poster
Aug 31, 2011
30,388
30,149
Just curious if this can be automated via Applescript/shell script? Perhaps even Automator?

My son had an energy project for his class tonight which has me thinking.

Generally I leave my QS on at full power with the screens set to shut off by a certain amount of time. With the type of processors I have I don't have the power setting in the Energy Settings pane to reduce their power draw.

But I do have the ability to switch one CPU off whenever I feel like it. So, I was thinking some sort of Applescript/shell script/automater feature that would shut off the second CPU whenever my screens go dark. I don't have an issue with doing that if I'm not at the Mac. But for a few reasons I'd rather avoid shutting the Mac off entirely.

I can automate the trigger, but have no idea where I'd find any scripting commands to control shutting off a cpu.

Ideally, when getting back on again the script would work in reverse and turn the second CPU back on.

Even if it's GUI scripting I can do that, I just need an idea of the commands.

Anyone have any idea?
 
Just curious if this can be automated via Applescript/shell script? Perhaps even Automator?

My son had an energy project for his class tonight which has me thinking.

Generally I leave my QS on at full power with the screens set to shut off by a certain amount of time. With the type of processors I have I don't have the power setting in the Energy Settings pane to reduce their power draw.

But I do have the ability to switch one CPU off whenever I feel like it. So, I was thinking some sort of Applescript/shell script/automater feature that would shut off the second CPU whenever my screens go dark. I don't have an issue with doing that if I'm not at the Mac. But for a few reasons I'd rather avoid shutting the Mac off entirely.

I can automate the trigger, but have no idea where I'd find any scripting commands to control shutting off a cpu.

Ideally, when getting back on again the script would work in reverse and turn the second CPU back on.

Even if it's GUI scripting I can do that, I just need an idea of the commands.

Anyone have any idea?

Take a look at Automator (http://www.macosxautomation.com/automator/), it should be able to do what your describing. If you don't like Automator it should be possible to accomplish with Applescript, however you will have to do some reasearch into the required commands.
 
Take a look at Automator (http://www.macosxautomation.com/automator/), it should be able to do what your describing. If you don't like Automator it should be possible to accomplish with Applescript, however you will have to do some reasearch into the required commands.
Well, I started the research, but ran into a Google wall of irrelevant returns which is why I asked here. I'll take a look at Automator tonight though.
 
Well, I started the research, but ran into a Google wall of irrelevant returns which is why I asked here. I'll take a look at Automator tonight though.

There is a world-wide-web of info out there that can result in a lot of time chasing unrelated or useless information. Automator has the ability to record manual tasks, and play them back as part of a workflow. In your case, automating the task of opening Sys Prefs and turning off 1 CPU should be easy. (Open Automator, select Automator Help from the Help menu, search for "record." The first article explains how to record actions ;))

The tricky part will be running your script AFTER the screen saver activates. However you should be able to use a github project called ScriptSaver to help with that (https://swannman.github.io/scriptsaver/).

Enjoy!
 
There is a world-wide-web of info out there that can result in a lot of time chasing unrelated or useless information. Automator has the ability to record manual tasks, and play them back as part of a workflow. In your case, automating the task of opening Sys Prefs and turning off 1 CPU should be easy. (Open Automator, select Automator Help from the Help menu, search for "record." The first article explains how to record actions ;))

The tricky part will be running your script AFTER the screen saver activates. However you should be able to use a github project called ScriptSaver to help with that (https://swannman.github.io/scriptsaver/).

Enjoy!
Cool! Thanks! I actually was going to look at Lingon or DSW (Do Something When) but this looks like the right ticket.
 
OK. This is a GUI Scripting thing!

Code:
tell application "System Preferences"
	activate
	set current pane to pane id "com.apple.preference.hardware"
	tell application "System Events"
		tell process "System Preferences"
			set perform_changes to true
			if perform_changes is true then
				-- MAKE CHANGES
				click checkbox 1 of row 2 of table 1 of scroll area 1 of window "Processor"
			end if
		end tell
	end tell
end tell

This will open System Preferences, call the Processor pane and click the checkbox for CPU 2.

The main problem was trying to find out what the element was being called.

Now to wrap it up so it does this silently and in the background, code I already have at hand when I GUI scripted Internet Sharing.
[doublepost=1456896184][/doublepost]OK. Turns out my "silently in the background" scripts I used previously were because I had abandoned GUI scripting and went with shell script.

So, we'll start from square one again. Right now this is good enough. We'll see if it can be improved in the future.

I'm using the scriptsaver link Hack mentioned earlier.

ENABLE:
Code:
tell application "GrowlHelperApp"
	set the allNotificationsList to {"Notification 1", "Notification 2"}
	set the enabledNotificationsList to {"Notification 1", "Notification 2"}
	register as application ¬
		"CPU_Toggle" all notifications allNotificationsList ¬
		default notifications enabledNotificationsList ¬
		icon of application "System Preferences"
end tell

tell application "System Preferences"
	activate
	set current pane to pane id "com.apple.preference.hardware"
	tell application "System Events"
		tell process "System Preferences"
			if (value of checkbox 1 of row 2 of table 1 of scroll area 1 of window "Processor") is equal to 0 then
				click checkbox 1 of row 2 of table 1 of scroll area 1 of window "Processor"
				tell application "GrowlHelperApp"
					notify with name "Notification 1" title "CPU2 Enabled" description "CPU2 is now enabled" application name "CPU_Toggle"
				end tell
			else -- Deactivates CPU Toggle if it is activated
				if (value of checkbox 1 of row 2 of table 1 of scroll area 1 of window "Processor") is equal to 1 then
					tell application "System Preferences"
						quit
					end tell
					tell application "GrowlHelperApp"
						notify with name "Notification 2" title "CPU2 Enabled" description "CPU2 is already enabled" application name "CPU_Toggle"
					end tell
				end if
			end if
		end tell
	end tell
	tell application "System Preferences"
		quit
	end tell
end tell

DISABLE:
Code:
tell application "GrowlHelperApp"
	set the allNotificationsList to {"Notification 1", "Notification 2"}
	set the enabledNotificationsList to {"Notification 1", "Notification 2"}
	register as application ¬
		"CPU_Toggle" all notifications allNotificationsList ¬
		default notifications enabledNotificationsList ¬
		icon of application "System Preferences"
end tell

tell application "System Preferences"
	activate
	set current pane to pane id "com.apple.preference.hardware"
	tell application "System Events"
		tell process "System Preferences"
			if (value of checkbox 1 of row 2 of table 1 of scroll area 1 of window "Processor") is equal to 1 then
				click checkbox 1 of row 2 of table 1 of scroll area 1 of window "Processor"
				tell application "GrowlHelperApp"
					notify with name "Notification 1" title "CPU2 Enabled" description "CPU2 is now disabled" application name "CPU_Toggle"
				end tell
			else -- Deactivates CPU Toggle if it is activated
				if (value of checkbox 1 of row 2 of table 1 of scroll area 1 of window "Processor") is equal to 0 then
					tell application "System Preferences"
						quit
					end tell
					tell application "GrowlHelperApp"
						notify with name "Notification 2" title "CPU2 Enabled" description "CPU2 is already disabled" application name "CPU_Toggle"
					end tell
				end if
			end if
		end tell
	end tell
	tell application "System Preferences"
		quit
	end tell
end tell

It's calling Growl each time to notify me.
 
  • Like
Reactions: Hack5190
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.