Applescript expert needed: Why does this script fail? (Play MOV files in succession)

Discussion in 'Mac Programming' started by tarek01, Feb 20, 2010.

  1. tarek01 macrumors newbie

    Joined:
    Sep 6, 2009
    #1
    This is an Applescript that automatically plays a folder of QuickTime movies in succession and it works flawlessly (Credit goes to macdosth for creating the script):

    Code:
    tell application "QuickTime Player"
    	-- get the list of movie files to be played
    	tell application "Finder"
    		set myfolder to "Mac HD:Movies"
    		set filelist to list folder myfolder
    	end tell
    	-- play the movie files one after another
    	set myfolder to "Mac HD:Movies:"
    	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
    What I would like to do is add a prompt that asks which folder contains the movies that are to be played. Here's the modified code, but it doesn't work. Can anyone figure out what's wrong?

    Code:
    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 --unsure about this line
    	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
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Try changing the the choose folder line to:

    Code:
    set myfolder to (choose folder with prompt "Select the folder containing QuickTime moves...") as string
    
    I still get errors though. For example what if there is a .DS_Store file in the folder?
     
  3. tarek01 thread starter macrumors newbie

    Joined:
    Sep 6, 2009
    #3
    Awesome! I suspected it was a tiny fix. Thanks robbie!

    It still needs tweaking to add the ability to detect the file type. But even so, this little script far outweighs its imperfections if you apply it to folders dedicated to contain only video files. Great for viewing tutorials containing dozens of MOVs!
     
  4. tarek01 thread starter macrumors newbie

    Joined:
    Sep 6, 2009
    #4
    Here's the modified working script. I removed the PRESENT MOVIE setting, just as a preference. Is it possible for it to play files inside sub-folders if the chosen folder ONLY contains folders?

    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
     

Share This Page