Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

anp925

macrumors newbie
Original poster
Feb 18, 2009
3
0
Let me start off saying I have experience programming in C, C++, and matlab, but no experience with applescripts.

I'm hoping someone on this site will be kind enough to put together a script for me that I think should be fairly simple for someone who knows what they are doing. I am using quicktime pro, and here's what I'd like.

I have 30 min videos and I need to analyze what's happening in them in 15 sec bins (or some other number that I can change later). It would be extremely useful if I could either a) use a script to stop play after 15 sec or b) automatically cut up the video in 15 sec sections. not necessary, but useful, might also be to click the forward and backward buttons and jump my a specific number of seconds. The first option is better. I got on the quicktime developer's site and saw functions such as setmovieselection etc, but really don't know how to use applescript yet.

thanks for anyone who helps!

-adam
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Here you go. I made QuickTime Player crash when trying it on a 720p movie though ;)
Code:
tell application "QuickTime Player"
    -- get active movie
    set doc to document 1
    -- calculate segments
    set movcut to 15
    set dursecs to (duration of doc) / 1000
    set c to dursecs / movcut
    -- loop each segment
    repeat with i from 0 to c
        -- set segment selection
        set selection start of doc to (i * movcut) * 1000
        set selection end of doc to (i * movcut + movcut) * 1000
        -- copy selection into new movie
        copy doc
        set newdoc to make new document
        paste newdoc
    end repeat
end tell
Edit: it'd probably be better if I didn't convert to seconds, and instead divide by (movcut*1000) to preserve accuracy..
 

anp925

macrumors newbie
Original poster
Feb 18, 2009
3
0
Thanks

Thanks a lot!
I really appreciate the effort.

I'll try to make some modifications and see what happens. I might be back with more questions.

-a
 

anp925

macrumors newbie
Original poster
Feb 18, 2009
3
0
Another question

Is there a way to make it wait until I have played the selection before moving to the next selection?

basically, before the next increment in the repeat loop, I'd like to play the clip. Then press a key, and have the loop resume. Some of the movies are actually quite long (1 hour plus), and I don't really need to actually have each clip in a separate window because there are so many of them

it seems simple, but again applescript language is totally unfamiliar. I've been searching websites for over an hour, and haven't come up with much.

any help is appreciated!

-a
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
If you don't want new movies just remove the code after the part that sets the start of the selection.

As for pausing, I don't know if you can do that within the script. You would need to have to store the values first, and then allow for a way to continue processing. That might be more suited for AppleScript Studio.
 

macdosth

macrumors newbie
Jul 26, 2009
4
0
AppleScript for playing movies one AFTER another in QuickTime

The following script plays a bunch of movies in QuickTime one AFTER another -- it waits for a movie to finish playing, then waits for a delay period, then closes that window, and opens the next movie. It took me hours of browsing to get all the info required to put this script together -- am surprised this is the case for an Apple product!
-----------------------------------------------------------------------------
tell application "QuickTime Player"
-- get the list of movie files to be played
tell application "Finder"
set myfolder to "VideoCD:MPEGAV"
set filelist to list folder myfolder
end tell
-- play the movie files one after another
set myfolder to "VideoCD:MPEGAV:"
repeat with movie1 in filelist
-- get the full path to the movie
set fullmovie1 to myfolder & movie1
-- play the movie
open fullmovie1
present document 1 scale screen
-- wait until movie is done
repeat until (get done of document 1)
end repeat
-- pause for a few seconds before next movie
-- (delay of greater than 2 seconds doesn't seem to work)
delay 2
-- close the played movie
close document 1
end repeat
end tell
 

tarek01

macrumors newbie
Sep 6, 2009
8
0
macdosth, you are D man! I too have always wondered why a sequential playback of multiple Quicktime movies was never included or created. It's not always practical to resort to cutting/pasting into one large file. Phenomenal contribution. This will be highly useful. Thank you!
 

tarek01

macrumors newbie
Sep 6, 2009
8
0
I tried modifying macdosth's script to ask what folder to use, but I can't get it to work...
--------------------------------------------------
tell application "QuickTime Player"
-- get the list of movie files to be played
tell application "Finder"
set myfolder to (choose folder with prompt "Select the folder containing QuickTime moves...")
set filelist to list folder myfolder
end tell
-- play the movie files one after another
set myfolder to myfolder --(???) not sure what should go here
repeat with movie1 in filelist
-- get the full path to the movie
set fullmovie1 to myfolder & movie1
-- play the movie
open fullmovie1
present document 1 scale screen
-- wait until movie is done
repeat until (get done of document 1)
end repeat
-- pause for a few seconds before next movie
-- (delay of greater than 2 seconds doesn't seem to work)
delay 2
-- close the played movie
close document 1
end repeat
end tell
--------------------------------------------------

Can anyone figure out how to do this?
 

mysterytramp

macrumors 65816
Jul 17, 2008
1,334
4
Maryland
I tried modifying macdosth's script to ask what folder to use, but I can't get it to work...

I think your problem (or a problem) is in these lines:

Code:
		set myfolder to (choose folder with prompt "Select the folder containing QuickTime moves...")

[...]

		set fullmovie1 to myfolder & movie1

In macdosth's script, he sets myfolder manually [set myfolder to "VideoCD:MPEGAV"], whereas you use choose folder.

In his script, myfolder is a string, therefore "set fullmovie1 ..." line works fine.

choose folder returns an alias to the folder, not a string. Therefore you can't just concatenate a filename to the end. The fix for you would be something like:

Code:
		set myfolder to ((choose folder with prompt "Select the folder containing QuickTime moves...") as text)

You'll get a string back that you can use later in the script.

[Brief sermon ... you would have seen the error yourself if list folder weren't so permissive on what data it accepts ... end of sermon]

BTW, this script is burping on the "present document ..." line so I'm assuming you folks are running Leopard. I'm on SL, so I can't check other QT-related issues.

mt
 

tarek01

macrumors newbie
Sep 6, 2009
8
0
Thanks mystery. I just found your same solution from another thread. Yes, I'm on a Leopard machine. SL must require a small variation for the "present" part. Here's the updated and working script (without the PRESENT MOVIE setting):

Code:
tell application "QuickTime Player"
	-- get the list of movie files to be played
	set myfolder to (choose folder with prompt "Select the folder containing QuickTime moves...") as string
	set filelist to list folder myfolder
	-- play the movie files one after another
	repeat with movie1 in filelist
		-- get the full path to the movie
		set fullmovie1 to myfolder & movie1
		-- play the movie
		open fullmovie1
		-- wait until movie is done
		repeat until (get done of document 1)
		end repeat
		-- pause for a few seconds before next movie
		-- (delay of greater than 2 seconds doesn't seem to work)
		delay 2
		-- close the played movie
		close document 1
	end repeat
end tell

So, how could permissions be implemented to detect filetypes? It'd be great if it were able to play files in subfolders. I'm using this to play tutorial movies continuously, and they're usually organized in subfolders.
 

mysterytramp

macrumors 65816
Jul 17, 2008
1,334
4
Maryland
Here's a simple script to travel through a folder tree:

Code:
on doOneFile(fileItem)
	tell application "Finder"
		-- these two lines just to show code is
		-- traveling through folder tree
		-- here's where you'd do your real business
		set fileName to name of fileItem
		display dialog fileName 
	end tell
end doOneFile

on processFiles(listOfFiles)
	repeat with oneItem in listOfFiles
		doOneFile(oneItem)
	end repeat
end processFiles

on processFolders(listOfFolders)
	repeat with oneFolder in listOfFolders
		tell application "Finder"
			set fileList to files of oneFolder
			my processFiles(fileList)
			set folderList to folders of oneFolder
			my processFolders(folderList)
		end tell
	end repeat
end processFolders


tell application "Finder"
	set myFolder to choose folder
	set fileList to files of myFolder
	my processFiles(fileList)
	set folderList to folders of myFolder
	my processFolders(folderList)
end tell

Where it says "display dialog filename" is where you'd put your code to play a movie.

I tested this with a simple folder tree and I'm not sure you can be certain movies will appear in a certain order, unless your movies use a certain naming convention. (Something like: 01- Folder: 01 - Movie, 02 - Movie; 02 - Folder: 01 - Movie, 02 - Movie, 03 - Movie; 03 - Folder: 01 - Movie; etc.)

Bear in mind, this operates on file items, not strings that represent file paths. Sometimes this way is better, sometimes not.

If you need the path, you need to coerce a file item to a string, and you'll get the HFS path.

mt
 

mysterytramp

macrumors 65816
Jul 17, 2008
1,334
4
Maryland
(picking up from your other thread ...)

list folder gives a list of filenames. If you had a list of file items, you'd have some more control. How about doing something like this:

Code:
tell application "Finder"
	set fileList to files of (choose folder)
	repeat with aFile in fileList
		if name extension of aFile is "MOV" then
			-- operate on aFile
		end if
	end repeat
end tell

Pardon me for leaving a lot for you so spackle over. I don't have a lot of movies on my hard disk to see exactly how this works. If you need more help stitching this all together, let me know.

mt
 

macdosth

macrumors newbie
Jul 26, 2009
4
0
Glad to know the script is useful.

I now run into a problem where .DS_Store files are present in the movie folders and that breaks the script. The following version works around this problem, it presents all files in a single folder. It also lets the user identify the folder, rather than hardcoding it. However, see the second version to be posted later, where I try to display files from a hierarchy of folders, that one breaks.


===Display JUST THE movie files in a single folder, one AFTER another=====

global movielist -- list of movies in a particular folder
global topmoviefolder -- alias
global moviefolder -- Mac full pathname
global movieExt -- filename extensions for movies

set movieExt to {".wmv", ".dat", ".avi", ".mpg"}

-- first start with the topmost folder containing the movies..
tell application "Finder"
-- prompt user for Folder containing the movies
set topmoviefolder to (choose folder with prompt "Select the folder containing QuickTime moves...") -- as string
display dialog topmoviefolder as text

-- now, some convoluted gymnastics to get the Mac full pathname of the chosen folder
-- (someone please replace this with a single command!)
set moviefolder to (topmoviefolder as text)
set moviefolder to POSIX path of moviefolder
set moviefolder to (POSIX file moviefolder) as string
-- end gymnastics
display dialog moviefolder

-- debug output..
set movielist to list folder topmoviefolder
display dialog movielist as string

my displayMovies(movielist)

end tell -- Finder


on displayMovies(movielist)
-- play the movie files one after another
tell application "QuickTime Player"
repeat with movie1 in movielist
repeat with Ext in movieExt
if movie1 ends with Ext then
-- get the full path to the movie
set fullmovie1 to moviefolder & movie1
-- play the movie
open fullmovie1
present document 1 scale screen
-- wait until movie is done
repeat until (get done of document 1)
end repeat
-- pause for a few seconds before next movie
-- (delay of greater than 2 seconds doesn't seem to work)
delay 2
-- close the played movie
close document 1
end if -- file name extension check
end repeat -- file ext
end repeat
end tell -- QuickTime
end displayMovies

=================================================
 

macdosth

macrumors newbie
Jul 26, 2009
4
0
This version TRIES TO present all the movie files in a hierarchy of folders, however it barfs on some AppleScript problem with using file aliases versus full Mac pathnames in script subroutines. Anyone game to quickly fix this script?

Thanks.

=================================================
TRY TO display all the movies in a folder hierarchy ONE AFTER ANOTHER, skipping over non-movie files while traversing the entire folder hierarchy.
The script currently breaks on some AppleScript issue with using file aliases versus full Macintosh pathnames.. perhaps someone knows what is broken and
can fix this?
=================================================

global movielist -- list of movies in a particular folder
global topmoviefolder -- alias
global moviefolder -- Mac full pathname
global movieExt -- filename extensions for movies

set movieExt to {".wmv", ".dat", ".avi", ".mpg"}

-- first start with the topmost folder containing the movies..
tell application "Finder"
-- prompt user for Folder containing the movies
set topmoviefolder to (choose folder with prompt "Select the folder containing QuickTime moves...") -- as string
display dialog topmoviefolder as text

-- now, some convoluted gymnastics to get the Mac full pathname of the chosen folder
-- (someone please replace this with a single command!)
set moviefolder to (topmoviefolder as text)
set moviefolder to POSIX path of moviefolder
set moviefolder to (POSIX file moviefolder) as string
-- end gymnastics
display dialog moviefolder

-- debug output..
set movielist to files of topmoviefolder
display dialog movielist as string
set movieSubFolders to folders of topmoviefolder
display dialog movieSubFolders as text
-- the above works fine here, but not in the other "subroutines" below!

my displayFolder(topmoviefolder)

end tell -- Finder


on displayFolder(moviefolder)
-- first display all movie files in the folder; folder may contain non-movie files
try
set movielist to files of moviefolder
display dialog movielist as string
my displayMovies(movielist)
end try

-- next, display any movies in each of the subfolders

try
set movieSubFolders to folders of moviefolder
display dialog movieSubFolders as text
repeat with moviefolder in movieSubFolders
display dialog moviefolder as text
my displayFolder(moviefolder)
end repeat
end try
end displayFolder

on displayMovies(movielist)
-- play the movie files one after another
tell application "QuickTime Player"
repeat with movie1 in movielist
repeat with Ext in movieExt
if movie1 ends with Ext then
-- get the full path to the movie
set fullmovie1 to moviefolder & movie1
-- play the movie
open fullmovie1
present document 1 scale screen
-- wait until movie is done
repeat until (get done of document 1)
end repeat
-- pause for a few seconds before next movie
-- (delay of greater than 2 seconds doesn't seem to work)
delay 2
-- close the played movie
close document 1
end if -- file name extension check
end repeat -- file ext
end repeat
end tell -- QuickTime
end displayMovies

=================================================
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.