--
-- add_videos_to_iTunes.applescript
--
-- Call this script via cron every 10 minutes, by
-- adding the following line to your crontab file:
--
-- */10 * * * * /usr/bin/osascript /Users/me/bin/add_videos_to_iTunes.applescript
--
-- To edit your crontab file, just open a terminal
-- and run the command "crontab -e".
--

set new_files_folder to "Macintosh HD:Users:me:videos:todo"
set finished_files_folder to "Macintosh HD:Users:me:videos:iTunes"

set new_files_list to list folder new_files_folder without invisibles
repeat with filename in new_files_list
	set full_filename to new_files_folder & ":" & filename
	set mod_date to modification date of (info for file full_filename)
	if mod_date is less than ((get current date) - 5 * minutes) then
		try
			--display dialog full_filename
			tell application "Finder" to move file full_filename to folder finished_files_folder
			set full_filename to finished_files_folder & ":" & filename
			tell application "iTunes" to add file full_filename to library playlist 1
		end try
	end if
end repeat
