Thought I'd share this, I've set this up as a Self Service item, it relies on the built-in sysdiagnose tool, and then puts together a nice user-friendly e-mail so they can submit their woes to us.
As a side note, the icon I chose is a stack of *actual* logs... you know, like portions of trees... apparently this was somewhat entertaining to some folks here....
Enjoy!
#!/bin/bash
# Set Variables
# Who's the current console user?
LOGGEDIN=`who | grep console | awk '{print $1}'`
# What's the default mail client for the logged in user?
DEFAULTMAIL=`defaults read /Users/$LOGGEDIN/Library/Preferences/com.apple.LaunchServices.plist | perl -e 'while(<>) {push @lines, $_; m~mailto~ and last} $_ = $lines[-2]; s~[^"]+"~~;s~";~~;print'`
# Get the Computer Name
COMPUTER=`hostname`
# The file that sysdiagnose created to add as an attachment
FILE=`ls -ltr /var/tmp | tail -1 | awk '{print $9}'`
# Name of the disk the OS is booted off of for AppleScript to be happy...
BOOTDISK=`diskutil info / | grep "Volume Name" | cut -c 30-50`
# Path on local machine to CocoaDialog
CD="/Path/To/CocoaDialog.app/Contents/MacOS/CocoaDialog"
# Simple expect to get the return for sysdiagnose to run
expect <<- DONE
set timeout -1
spawn sysdiagnose
# Look for prompt
expect "*?ontinue*"
# send blank line (
) to make sure we get back to gui
send -- "
"
expect eof
DONE
# Based on what default mail client the user is using, put everything together in a nice mail for them
if [ "$DEFAULTMAIL" == "com.apple.mail" ];
then
echo "tell application "Mail"
set theContent to ("Included are System Diagnostic logs from the computer ${COMPUTER}. \\r \\r Please include any details about what was going on on your machine that caused you to send us this information. \\r \\r Affected Application: \\r Is the problem reproducable: \\r Steps to reproduce: \\r Expected Results: \\r Actual Results: \\r \\r ")
set theEmail to make new outgoing message with properties {visible:true, subject:"System Diagnostic Logs from ${COMPUTER}", content:theContent}
tell theEmail
make new recipient at end of to recipients with properties {address:"administrator@example.com"}
make new attachment with properties {file name:"$BOOTDISK:var:tmp:$FILE" as alias} at after last paragraph
end tell
end tell" | osascript
elif [ "$DEFAULTMAIL" == "com.microsoft.outlook" ];
then
echo "tell application "Microsoft Outlook"
set theContent to ("Included are System Diagnostic logs from the computer ${COMPUTER}. <br><br> Please include any details about what was going on on your machine that caused you to send us this information. <br><br> Affected Application: <br> Is the problem reproducable: <br> Steps to reproduce: <br> Expected Results: <br> Actual Results: <br><br> ")
set theAttachment to file "$BOOTDISK:var:tmp:$FILE" as alias
set newMessage to make new outgoing message with properties {subject:"System Diagnostic Logs from ${COMPUTER}", content:theContent}
make new recipient at newMessage with properties {email address:{name:"Administrator", address:"administrator@example.com"}}
make new attachment at newMessage with properties {file:"$BOOTDISK:var:tmp:$FILE" as alias}
open newMessage
end tell" | osascript
# Not using Mail or Outlook? Here's the file and what to do with it...
else
$CD ok-msgbox --text "No Acceptable Mail Client Found"
--informative-text "It appears that neither Apple Mail or Microsoft Outlook are being used as your default mail applications. If you wish to send the diagnostic report please send the resulting file to administrator@example.com"
--no-newline --float
logger "No suitable mail client found"
exit 0
fi