QuickTime Logger

Has anybody made script which logs what movies user watches using QuickTime. Like this:

August 14, 2007 08:11:25 / Apple Store Opening.mpg
August 14, 2007 08:13:45 / MacBook.mpg

I see several possible ways to go:
a) you open the files with a script (choose file) → log

b) a stay open script could monitor if QT is running
and if so check if a new movie has been opened → log
or compare the previous list with the log and append if needed.

c) use some deeper system functions instead of AS.
I couldn’t help with that.

I was also thinking this but it seems too difficult to me, so lets forget it.

My thought would be to use launchd to watch a folder for changes, and then when changes happen run an applescript to log the event. Craig Smith has a tutorial which details most of this process. It could probably be adapted to suit your needs.

http://macscripter.net/articles/440_0_10_0_C/

Then the question becomes “what folder to watch”. Since quicktime player has a “open recent” menu under the file menu, I would assume that every time a movie is opened quicktime player logs the new movie to a file. I haven’t looked but that log file is probably a .plist file in the preference folder… which means you can watch whatever folder that log file is in.

My friend, you give up rather quickly. Well, I might not see what you would want a logger for, but that doesn’t matter.
You put A out on this board, we give you B and you figure C then someone will come up with D and before
we arrive at Z, your logger is born. :lol:

Regulus’ idea sounds like the way to go. It sounds like the least overhead inducing route.

Here’s my sketch of the b) route:

property movieCount : 0
property fileNameList : {}

on launch
	idle 1
end launch

on idle
	tell application "System Events"
		set processesNameList to name of processes
		if "QuickTime Player" is in processesNameList then
			tell application "QuickTime Player"
				set movieCountNew to count movies
				if movieCount < movieCountNew then my logUsage()
				set movieCount to movieCountNew
			end tell
		end if
	end tell
	return 1
end idle

to logUsage()
	-- compare open file names to list and log if needed
	beep 2
end logUsage

Save as a “Stay Open” application and run.
Now every time you open a file with QuickTime Player, you’ll hear 2 beeps.

Now that I started, I couldn’t stop until I had this:

property movieCount : 0
property fileNameList : {}

on launch
	idle 1
end launch

on idle
	tell application "System Events" to 	set processesNameList to name of processes

	if "QuickTime Player" is in processesNameList then
		tell application "QuickTime Player"
			try
				set movieCountNew to count movies
				set fileNameListNew to original file of movies
			on error eMsg number eNum
				-- probably no files open, just in case it's something else, let's output the message
				display dialog eMsg & " (" & eNum & ")"
				set movieCountNew to 0
				set fileNameListNew to {}
			end try
			if movieCount < movieCountNew then
				repeat with thisItem in fileNameListNew
					if thisItem is not in fileNameList then
						-- write entry to file
						my logUsage(thisItem)
					end if
				end repeat
			end if
			set movieCount to movieCountNew
			set fileNameList to fileNameListNew
		end tell
	end if
	return 1
end idle

to logUsage(filePathName)
	-- write log you will find examples on writing files on bbs.applescript.net
	beep 2
end logUsage

All that remains is the handler that writes to file. There are a bunch of posts with examples on how to do that.
:smiley:

If you read the article Regulus mentioned, it isn’t hard to convert route b) into c)