Get MacBook to say Thank You when plugging in the power cord? 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"
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.