Choose a random movie from the movie section of iTunes

Hey All,
I’m writing 2 scripts that involve choosing random files. I am automating my apartment with several macs and I started with this script:

set sourceFolder to ((path to documents) & "speakit") as string
display dialog sourceFolder

set myfiles to every file of alias sourceFolder whose name contains "say"
tell application "System Events"
	open some file of alias myfiles
end tell

The idea is using speakable items. I will put this in the speakable items folder named “what’s up?” and when I say “Computer, what’s up?” it will choose from a folder of scripts saved as applications that make the computer say different phrases. I need the right way to point the script to the folder of phrases I have in the Documents folder. Hopefully that’s not confusing. So far I’ve had no luck.

AAANYways… I also wanted to be able to say “play a movie” and have the computer choose from the movies section of iTunes and play it in full screen. Anyone have any ideas?

Thanks!

Model: mac mini 1.66 core duo, macbook 2.0 core duo, emac g4 1.0, imac g4 800mhz
AppleScript: 2.2.1
Browser: Safari 525.20.1
Operating System: Mac OS X (10.5)

Hi Brandon,

unfortunately I have no experience at all with speakable items.
You can play a random track in full screen with this code


tell application "iTunes"
	activate
	tell playlist "Movies" to play some file track
end tell
delay 2
tell application "System Events" to tell process "iTunes" to keystroke "f" using command down

The script must be run as an application, if you run it from Script Editor,
Script Editor itself becomes frontmost after finishing the script and the full screen mode vanishes

This line should be as follows…

set sourceFolder to (path to documents folder as string) & "speakit"

In other words, the path to the documents folder has to be coerced to a string first so that you can add the string “speakit” to it.

Here’s the whole script fixed…

set sourceFolder to (path to documents folder as string) & "speakit"
tell application "Finder"
	set myFiles to every file of folder sourceFolder whose name contains "say"
	open some item of myFiles
end tell

Regarding StefanK’s suggestion of how to get and play the movie full screen, you can always use quicktime player to play the movie like so…

tell application "iTunes"
	tell playlist "Movies" to set thisMovie to some file track
	set thisMoviePath to location of thisMovie
end tell

tell application "QuickTime Player"
	activate
	open thisMoviePath
	rewind document 1
	present document 1 scale screen
	try
		repeat until done of document 1 is true
			delay 1
		end repeat
		close document 1
	end try
end tell

Notice the repeat loop. That will watch qt player and when the movie is finished it will close the movie file.

That’s awesome guys thanks so much. I’ll be posting a how-to for all of what I’m working on in regards to home automation via older macs. I haven’t spent a cent so far and I’m just using my old computers I never threw away! Thanks again!