Weekly Report of Activity sent to an email

Summary: I am trying to build an applescript that will email me every xx days with a summary of events.

Explanation: I manage a computer that sits in a bar. Once in a while, a bartender will add a cd full of music, or reboot, or pull up a website, whatever.

Primarily, when new music is added, I need to go into iTunes and update Artist, Year, Genre, etc. so that the smart lists will have the correct music.

The issue is, essentially, nobody tells me when new music is added, so I never know when to go check!

Result:
Every xx days, I would like to get an email from the computer with a report of:

  • New music added to iTunes in the last xx days
  • Items added to folders (and all sub folders) in xx days
  • Items modified in itunes (id3 tag, genre, check/uncheck, year, artist, etc) in xx days
  • Websites visited in the last xx days (safari history)
  • computer uptime report
  • ?? perhaps other useful information ??

I can schedule the applescript to run via iCal, and I know you can send emails through Mail… i just don’t know how to collect the information to put INTO the email to send.

Possibles: upon scrounging the internet, I found scripts to send emails, report uptime, show when something was added to a folder (using smart folder triggers). I am just not well versed enough to pull it all together.

Here’s the individual scripts I have so far:

– to eMail:
tell application “Mail”
set theNewMessage to make new outgoing message with properties {subject:“Summary Report”, content:“CONTENT HERE”, visible:true}
tell theNewMessage
make new to recipient at end of to recipients with properties {address:“user@email.com”}
send
end tell
end tell

– uptime:
do shell script “uptime”

Any help would be SUPER appreciated.

Model: Mini
Browser: Safari
Operating System: Mac OS X (10.5)

I am making progress:


-- Weekly Changes list 

-- Uptime 
set Uptime to do shell script "uptime"

-- Get List of files modified

set fileList to ""
set sortFolder to choose folder -- I'll hard code this folder after testing
set kDate to date (date string of ((current date) - (7 * days)))
-- set sortFolder to choose folder -- Replace when Live

tell application "Finder"
	set sortFiles to files of sortFolder whose (modification date) > kDate
	
	set fileCount to (count of sortFiles) as string
	set sortFiles to sort sortFiles by creation date
	repeat with aFile in sortFiles
		set aFile to name of aFile as string --remove "name of" for alias list
		set fileList to fileList & aFile & return & return
	end repeat
	
end tell

set theList to fileCount & " Files:" & return & return & fileList

-- Email Part 


tell application "Mail"
	set theNewMessage to make new outgoing message with properties {subject:"Summary Report", content:"Modified Last 7 Days: " & return & Return & theList & return & "Uptime: " & Uptime & return & return, visible:true}
	tell theNewMessage
		make new to recipient at end of to recipients with properties {address:"Email@mail.org"}
		send
	end tell
end tell

set theList to ""
tell application "Mail"
	-- quit
end tell

I think I got most of it… Some may be redundant, but that’s just because I want to ensure that there is no user interaction (minimizing)



-- Weekly Changes List Script

-- Uptime 
set Uptime to do shell script "uptime"

-- Get List of files modified

set fileList to ""
set sortFolder to alias "music:Music" -- Hard coded.
set kDate to date (date string of ((current date) - (7 * days)))
-- set sortFolder to choose folder -- Replace when Live

tell application "Finder"
	set sortFiles to files of sortFolder whose (modification date) > kDate
	
	set fileCount to (count of sortFiles) as string
	set sortFiles to sort sortFiles by creation date
	repeat with aFile in sortFiles
		set aFile to name of aFile as string --remove "name of" for alias list
		set fileList to fileList & aFile & return & return
	end repeat
	
end tell

set theList to fileCount & " Files:" & return & return & fileList

-- Get List of 7 Days old iTunes
tell application "iTunes"
	set thePlaylist to playlist "07 Days" -- This is a smart playlist of items added in the last 7 days
	
	set the playlist_count to the count of tracks of thePlaylist
	set playlist_data to {}
	
	tell thePlaylist
		repeat with i from 1 to the count of tracks
			tell track i
				set the end of the playlist_data to {"Item:  " & name & " - " & artist & return}
			end tell
		end repeat
	end tell
end tell


-- Email Part 
tell application "Mail" to activate
tell application "System Events"
	set visible of process "Mail" to false
end tell
tell application "Finder"
	set visible of process "Mail" to false
end tell
tell application "Mail"
	set miniaturized of window 1 to true
	set theNewMessage to make new outgoing message with properties {subject:"Fluid Weekly Computer Report", content:"Modified Last 7 Days: " & return & return & theList & return & "Uptime: " & Uptime & return & return & "iTunes Report: " & return & playlist_data & return, visible:false}
	tell theNewMessage
		make new to recipient at end of to recipients with properties {address:"user@email.org"}
		delay 10
		send theNewMessage
		delay 10
	end tell
end tell

set theList to ""


tell application "Mail"
	
	delay 10
	quit
end tell



If anyone can see places to make this better, I am all ears.