An AppleScript to email a notice upon user login

Dec 08, '04 08:34:00AM

Contributed by: Anonymous

I was looking for a way to have my machine notify me whenever it was booted (sort of a rudamtentry security system), and rather then buy some application to do this, I wrote a very small AppleScript to have Mail launch at boot and hide, send the message in the background, and then shut down mail. This is my first actual applescript and I'm sure there is a "better" way to do this, but it seemed to work for me. I tried to add comments to help any fellow "newbies" out there. Here's the script:

launch application "Mail"
tell application "Mail"
  -- set parameters for subject, body and sender
  set newMessage to make new outgoing message ¬
    with properties ¬
    {subject:"Your computer has Booted", content:"n/a", sender:"sender's email"}
  tell newMessage
    -- set Mail application to hide
    set visible to false
    -- set parameters for recipient
    make new to recipient at end of to recipients with properties ¬
      {address:"primary recipient's email address"}
    -- set parameters for CC recipient
    make new cc recipient at end of cc recipients with properties ¬
      {address:"secondary recipient's email address"}
  end tell
  send newMessage
end tell
--quit Mail application
tell application "Mail" to quit
delay 10
quit
[robg adds: This older hint contains a shell script that can be setup via cron to do similar things, and it includes info like the output from traceroute. The problem with this AppleScript solution is that it will be triggered only when someone logs in to your account (assuming it's been placed in your login items list), not when the machine itself is booted -- and the odds are quite low that a thief will have your login password, too.

The earlier hint, since it uses a script that runs with cron, will run regardless of whether the user is logged in or not. That earlier hint also includes a link in the comments to this page, which is a very robust Perl script for doing all sorts of remote notifications.

Note that all of these protection mechanisms can be bypassed if the thief is simply smart enough to boot from an OS X Install CD, or another hard drive. Still, they provide at least a bit of defense for a stolen machine. Consider adding an open firmware password to make that task more difficult...]

Comments (4)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20041130093947460