1

I would like to know how can to create an applescript which is executed when I connect the power cord to my MacBook. I would like it to say "Thank You"

1
2

This worked for me:

global thanks

on run
    set thanks to false
end run

on idle
    set battStatus to do shell script "pmset -g | grep \\*"
    if battStatus contains "AC Power" then
        if thanks is false then
            say "thank you"
            set thanks to true
        end if
    else
        set thanks to false
    end if
    return 1
end idle

Open Script Editor, Save as Application, Check "Stay open after run handler" to keep the program running. The only downside is you'll have to keep this program open at all times. You can set it to launch when you login. Maybe someone else has a better way to address this.

3
  • Isn't this going to consume a lot of CPU while running? May 10 '15 at 17:52
  • 1
    Not really. Its seems to be around 0.1% - less than a lot of background services.
    – Bowen
    May 10 '15 at 18:12
  • OK so it's fine :) May 10 '15 at 18:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .