Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

An AppleScript to email a notice upon user login System
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...]
    •    
  • Currently 1.00 / 5
  You rated: 1 / 5 (4 votes cast)
 
[10,401 views]  

An AppleScript to email a notice upon user login | 4 comments | Create New Account
Click here to return to the 'An AppleScript to email a notice upon user login' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A shell script to email a notice upon user login
Authored by: Black on Dec 08, '04 11:52:36AM
Rob is right that this isn't a terribly robust piece of security. Also, I'd think that opening Mail in the background and then closing it again would be a little annoying. If you really want to get this kind of notification when someone has logged into your account, a simple shell script would do:

#!/bin/sh
echo "Someone just logged in" | mail -s "Login notification" me@somewhere
Of course, the email address should be where you want the notification sent. if you wanted this to happen when you machine was actually booted, you could make this a system startup item (I'm sure the directions for doing that are around here somewhere).

[ Reply to This | # ]
A shell script to email a notice upon user login
Authored by: shemp9999 on Dec 08, '04 05:03:21PM
you can use a crontab to call the code at reboot.

@reboot echo "Someone just logged in" | mail -s "Login notification" me@somewhere


[ Reply to This | # ]
Open Firmware and Phoning Home
Authored by: BjarneDM on Dec 12, '04 01:54:05PM

You don't want to be too restrictive in setting up Open Firmware if you want you computer to phone home, because you do want the thief to be able to use the computer as it is - otherwise your computer obviously won't be able to phone home.

At the very least the thief has to be able to log into an account and use it to browse for a period.

You also want to discourage the thief from re-formatting the HD by making it interestingly enough to keep the computer in an un-altered state.

Thus, using Open Firmware in any way might very possibly defeat the purpose of your phone home script.

How do we then protect the - private and confidential - information on the HD? One way is setting the accounts up in this way:
1) Enable root account in order to get the 'Other' possibility in the login window with account names as icons
2) Have at least three accounts: a) administrator 2) guest *without* password 3) user
3) Use Netinfo Manager to change the numerical user and group numbers to something in the 400-range. This'll make the user account invisble in the login window, but you'll still be able to log in using the 'Other' choice. Of course you'll also have to use Terminal to change the owner and group numbers to the new settings on the user account. The user'll also be invisible in the normal accounts pref. pane
3) Use Netinfo Manager to change the home folder for the user to a 'hidden' folder (one starting with '.')
4) Switch on FileVault for user



[ Reply to This | # ]
Open Firmware and Phoning Home
Authored by: zs on Dec 13, '04 08:08:42PM
3) Use Netinfo Manager to change the home folder for the user to a 'hidden' folder (one starting with '.')
Careful with that. Nothing serious, but some applications won't open if there is any funny business in the path. Ultralingua comes to mind - I was using an omega (opt-z on US keyboards) to sort the folder it was in to the bottom. Not a problem if you don't try stuff out from your home directory, but it can be a frustration

---
zs

[ Reply to This | # ]