Answer
There sure is. All you need to do is create an AppleScript that checks to see if the AC cord is attached and then have it open programs depending on what comes back.
The shell command ioreg returns this information in the ExternalConnected property of AppleSmartBattery so we’ll just look for that. If it says “ Yes” then we know external power is connected. Anything else is battery.
There’s a space before the word “Yes” intentionally. The shell mucking done to get the answer leaves a space up front. It’s not terribly important to make it proper English as much as it is to know what the answer will be on our condition, so just make sure you leave that part alone and all will be well.
Clear out all of your programs from your startup items list in Accounts (except ones you want to always open) and then save the following script somewhere and add it to your startup items.
tell application "Finder"
set PowerConnected to do shell script "ioreg -l | grep ExternalConnected | cut -d'=' -f 2"
set ApplicationsFolder to folder "Applications" of home
set PowerFolder to folder "On Power" of ApplicationsFolder
set BatteryFolder to folder "On Battery" of ApplicationsFolder
if PowerConnected is " Yes" then
open every item of PowerFolder
else
open every item of BatteryFolder
end if
end tell
Open this in Script Editor.
Now create the folders it mentions (an Applications folder in your home, and then two folders inside it: “On Power” and “On Battery”). Add aliases to programs and documents to whichever folder you want and when the script is run it will open those items.
It’s pretty trivial to fix it so it doesn’t need the space anymore.
Heck, you could do something like
"ioreg -l | egrep -c ExternalConnected ?= ?Yes"which will spit out a count of matching lines (and it won’t care if there’s a space or not). So simply check if it equals 1.Oh, and your site has a serious comment problem. If I preview, it claims my comment body is empty (which it definitely isn’t). Trying to preview from that page claims it again, but this time gives me an actually-empty comment body.
What’s even weirder, is it actually previews properly.
Oh, and posting seems to work fine.
As I said, I’m sure there’s a way, but going the extra mile to remove one character didn’t suit me.
Thanks for the tip, though.
Comment preview works for me. Might be the input type you have selected?
It works like a charm!
although i did have to change
- set ApplicationsFolder to folder "Applications" of home
to
- set ApplicationsFolder to folder "Applications" of startup disk
as i don't maintain a separate applications folder within home
thanks again !
-andy
edit: but this method does add that few miliseconds to starting up as it checks the ioreg (?)