July 28, 2006
First, the major caveat:
THIS IS A NOT READY FOR PRIME-TIME APPLICATION
There's a bunch of things in it that would need to be done to make it something you want to rely upon. It's a demo/proof of concept that you could, if you like, use as a start for doing spiffy things with Apple Remote Desktop and AppleScript.
I wrote this because I wanted to see about using AppleScript with Apple Remote Desktop to create something a little more automatic than the Apple Remote Desktop menu widget allows for. The only real pain here was, unsurprisingly, Mail, which, in Mac OS X 10.4, is having some...issues in its dictionary. This is designed to work with both Mail and Entourage. The Mail setup is a bit more complex due to the workarounds I had to do when dealing with Mail's issues. I picked Mail because it's something that I can assume will be on every install of Mac OS X, and Entourage, because it's my client of choice, and it has one of the best AppleScript dictionaries of any email application. The whole thing is available as a proof of concept demo from here.
The Get help application, when run, pops a dialog allowing a user to enter a short problem description. This, and certain system information items are then packaged in an email to the person running the Apple Remote Desktop administrator console. It pops an alert notifying them that someone has a problem, with the problem description, User name (long and short), UID, home directory path, user computer name, user OS version, and user IP address. It also instructs Apple Remote Desktop to open an observe window on that computer. Obviously, you need to have the computers you run this on in Apple Remote Desktop for this to work. From my POV, this is of more use in a lab situation, but you could adapt it to almost any Apple Remote Desktop setup.
On the administrator machine, there are two paths for this to take:
With Entourage, the message from the user is grabbed by a rule, which kicks off an AppleScript. The AppleScript reads the contents of the email, parses them out, presnts the administrator with the alert message, and opens the observe window on the user's computer in Apple Remote Desktop.
With Mail, the end result is the same, but the process is more complicated. I simply couldn't get the display alert step to not terminally stall in Mail, so I had to come up with a workaround. In Mail, the message comes in, the rule grabs it, and kicks off the script. However, instead of directly popping the alert, the message contents are written to a text file in a directory in the administrator's Documents folder that has a folder action attached to it. Once that file is written, the script then has Apple Remote Desktop pop the observe window. The folder action graps the contents of the text file, and pops the alert telling you about the problem.
CAVEATS AND DISCLAIMER:
I tested this on 10.4.7 8j135. If you are running an earlier (or later) version of the Mac OS, and something doesn't work, I'll try to help you if I have the time. I didnt regression test this AT ALL, since it's just a proof of concept. I think there are a few things that just won't work in anything pre-Tiger, but if you want to make it work in Mac OS X 10.3, feel free. As always, there's no warranty or implied warranty or even possible warranty. If it works, great! If it doesn't, that's too bad. If it somehow magically, (and it would HAVE to be magic) causes your mac to melt, your toilet paper to turn to sandpaper, and your house to be posessed by an evil clown, not my problem. (Although I may want to buy your house, that would be so cool.) This is, as always, free. The source is included. Don't just blindly run this without reading this document AND THE SOURCE CODE. I comment heavily, so reading the source is of some benefit. Besides, it won't work if you dont' set up a few things in the "Get Help" application anyway.
Xmail is licensed by its creator, Jean-Baptiste LE STANG. Please go to his site for any Xmail info. I'd like to thank him for it, as it made this little demo MUCH nicer to write, and it's a way spiffy bit of code. If you're going to use this demo heavily, please do send him a donation.
My work in this is as always, creditware. It's free, do what you will with it. But, if you add some neat features, please, just leave my name in the comments somewhere, and add your own with your additions. I think it's really cool when I get an application, and I learn who did what on it. It's a history of the application, and I'm a history maven.
"Get Help" application component
Open up the "Get Help" application and set the blank properties to the values you need. For my testing, I just hardcoded stuff. That's a bit of a kludge I think, but again, this isn't a full-on application. (Don't complain, you aren't paying for it, now are you? No, no you are not.) If you want, you can probably pull the current user's email address and login info from the system or the Keychain if you like. There are also good reasons to staticly enter this information, there are good reasons not to, it's up to you. Either way, it's a fairly self-containted little applicaiton. It uses the Xmail 3.5 OSAX, which lives in the application's resources folder. Xmail is free, it's GPL'd. However, if you are going to actually use it, then please, do make a donation to it's author. The information is in the Xmail Readme, included in the zip for this application.
Installation: I recommend placing Get Help in the dock or desktop for whatever users you want to have access to this. MCX can be a help here.
Get Help's entire purpose is to send an email with specific information to a specific email address.
This is the script that you use with E'rage. Create a rule that is kicked off when the "Get Help" application's email comes in, (I used the subject line, but it's up to you), and attach this rule to it. That's it. Message comes in, rule runs script, script pops dialog and runs Apple Remote Desktop. Voila!
This is one of the scripts you use with Mail. Create a rule that is kicked off when the "Get Help" application's email comes in, (I used the subject line, but it's up to you), and attach this rule to it. That's the first part. This will get you the observe window in Apple Remote Desktop, and a text file written to ~/Documents/getmailhelp folder/. (Note that while this script will create the folder if it's not there, it will NOT handle the folder action parts automatically.) I keep this in the user's home directory, because well, that's what home directories are for, and in documents because Library is too much of a catchall, and this is creating documents. The text file is so that you can get the alert in the second part of using Mail with this. The second part is handeled by a folder action, mailgethelpfolderaction.scpt.
This is the script that handles popping the dialog, since Mail has issues with it. (Note, if anyone comes up with a fix for this, PLEASE let me know? firstname.lastname@example.org). This folderaction can be attached to any file, but the path in the script(s) assumes ~/Documents/getmailhelp folder/. The file hits the folder, the folder action reads the contents of the file, dumps them into an alert, and bang, done.
I have filed some bugs on Mail's AppleScript implementation based on Mail's quirks. Hopefully, they'll get fixed soon.
Again, this is just a proof of concept, to show some of the ways you can use AppleScript with Apple Remote Desktop, Mac OS X, and other applications to build support systems on your own. Sometimes, you just need to do it your way.
HUGE MONSTER THANK YOU!
To Mark Aldritt and Late Night Software for Script Debugger 4. I cannot imagine writing AppleScript without Script Debugger, nor do I wish to try. It has far too many features, like the reminders about open file handlers, the glory of its dictionary browsers, the ease of debugging things like folder actions and scripts run from email rules that just spoil me silly, and without it, I'd still be working on this. Actually, no, I wouldn't, because without Script Debugger, I'd not even bother trying.
CommentsWarning for Notes users: The commenting system uses HTML.
I know this will be scary for some of you, especially Notes fans. However, open standards, rah-rah.
If you want to use less-than or greater-than signs, or other similar characters that HTML reserves,
you'll simply have to learn to do it the HTML way. Luckily, HTML is kind of popular, no matter what
your re-educators have told you, and you can easily find help on the intertubes.