Idea [Action when Power Adapter Removed]

I have an idea
It is when the power adaptor is removed there will be a system beep or a screen flash. i would find this useful would anyone else could some one help me with the script?
thanks Luke

Hi Luke,

this is quite easy.
Save this as application with option stay open,
it checks every 5 seconds.

property flag : true

on run
	set flag to word 1 of (do shell script "pmset -g | grep '*'") is "AC"
end run

on idle
	set ACpower to word 1 of (do shell script "pmset -g | grep '*'") is "AC"
	if flag then
		if ACpower is false then
			say "power adaptor removed"
			set flag to false
		end if
		if ACpower then set flag to true
	end if
	return 5
end idle

If you want the script to quit after the message, this is sufficient

on idle
	if word 1 of (do shell script "pmset -g | grep '*'") is not "AC" then
		say "power adaptor removed"
		quit me
	end if
	return 5
end idle

i get a error. Can’t get word 1 of “”

What dose this mean

What happens with this?

display dialog (do shell script "pmset -g | grep '*'")

i dialog with a Cancle and ok button and no text

This is strange, because you can control all energy settings with pmset

What’s happening with this

display dialog (do shell script "pmset -g")

COmes up with some text about my computer.

very good, is there a line with the word Power included?
If yes, can you please post the complete line

Battery Power 0
AC Power 3*

What now?

That’s what I expected. Then the shell script with the grep command must work.

I don’t know, what’s going wrong :confused:

still get a Can’t get word 1 of “”.

Any thing else i can do?

try this subroutine

display dialog getPowerMode()

on getPowerMode()
	set p to paragraphs of (do shell script "pmset -g")
	repeat with i in p
		if i ends with "*" then return word 1 of i
	end repeat
end getPowerMode


do shell script "/usr/bin/pmset -g ps | /usr/bin/head -n 1 | /usr/bin/cut -d \\' -f 2"
--> Should return either "AC Power" or "Battery Power"

Does that work? I’m not sure why you’re not getting any output from Stefan’s first shell script…

im not sure but.
i want it so it will stay open. If the charger is unpluged it will say AC Removed.

Is this the same script?
PS im new at Applescript

Thanks Luke

Hi Luke,

first we must figure out to retrieve the data on your machine,
then we can complete the script.

Does one of last two solutions work?

Bruce Phillips’s Script dose not work. it opens and nothing comes up.
Your last script just opens up a window that says AC.

Heres my Model
MacBook Pro 15’ Early 2007

Model: MacBook Pro 15"
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

There is no display dialog command in Bruce’s script to display the result
But it should be displayed in the result window of Script Editor

oh ok. i wanted it as a applaction, will it work if a simpal dialog scripted is added??