See if you can fix this script supplied from Apple!
I came across a bunch of quicktime applescripts at http://www.apple.com/applescript/quicktime/. I thought they looked interesting so I decided to try them. Specifically I started with the ones about “chapters”. Basically with this bunch of scripts you can add chapter markers to quicktime movies. One problem… I can’t get it to work. Here’s what I did.
First I opened a quicktime movie which didn’t have any chapters in it. Then I ran the following script (Create Chapter Track.scpt) to add a blank chapter track to the movie… it worked fine.
tell application "QuickTime Player"
activate
try
if not (exists movie 1) then error "No movies are open."
stop every movie
-- CHECK FOR THE CORRECT VERSION
set QT_version to (QuickTime version as string)
set player_version to (version as string)
if (QT_version is less than "5.0") or ¬
(player_version is less than "5.0") then
error "This script requires QuickTime 5.0 or greater." & ¬
return & return & ¬
"Current QuickTime Version: " & QT_version & return & ¬
"Current QuickTime Player Version: " & player_version
end if
-- CHECK FOR QUICKTIME PRO
if QuickTime Pro installed is false then
set the target_URL to "http://www.apple.com/quicktime/download/"
display dialog "This script requires QuickTime Pro." & return & return & ¬
"If this computer is currently connected to the Internet, " & ¬
"click the "Upgrade" button to visit the QuickTime Website at:" & ¬
return & return & target_URL buttons {"Upgrade", "Cancel"} default button 2
ignoring application responses
tell application "Finder"
open location target_URL
end tell
end ignoring
error number -128
end if
tell movie 1
if the current chapter track is not {} then ¬
error "The front movie already has a chapter track."
set these_tracks to the name of every track
set the link_track to choose from list these_tracks with prompt "Pick the track which the new chapter track describes:"
if the link_track is false then error number -128
set the link_track to the link_track as string
set this_track to make new track at beginning with data "Start"
set enabled of this_track to false
set the name of this_track to "Chapter Track"
set chapterlist of track link_track to track "Chapter Track"
set the movie_length to the duration
tell chapter 1
set the time to 0
set the duration to movie_length
end tell
end tell
on error error_message number error_number
if the error_number is not -128 then
beep
display dialog error_message buttons {"Cancel"} default button 1
end if
end try
end tell
Then I wanted to add a chapter marker to the empty chapter track that I added. So I moved the playhead in quicktime a little bit into the movie and then ran the following script (Add Chapter at Current Time.scpt) to make a chapter at that spot in the movie.
tell application "QuickTime Player"
launch
activate
try
if not (exists movie 1) then error "No movies are open."
stop every movie
tell movie 1
set the chapter_track to the current chapter track
if the chapter_track is {} then ¬
error "This movie has no chapter track."
set the current_time to the current time
set the movie_end to the duration
-- get chapter info
set the chapter_list to the name of every chapter
set the start_list to the time of every chapter
set the duration_list to the duration of every chapter
-- check to make sure the current time is not on a chapter start
if the current_time is in the start_list then
error "There already is a chapter which begins at the current time."
else if the current_time is the movie_end then
error "You cannot add a chapter at the end of a movie."
end if
-- prompt for the new chapter name
set the new_chapter to ""
repeat
display dialog "Enter the name for the new chapter:" default answer new_chapter
set the new_chapter to the text returned of the result
if the new_chapter is "" then
beep
else if the new_chapter is in the chapter_list then
display dialog "There already is a chapter named "" & new_chapter & ""."
else
exit repeat
end if
end repeat
-- figure out how many chapters before the current time
set the chapter_count to the count of the start_list
set the chapter_index to the chapter_count
repeat with i from 1 to the chapter_count
set this_time to item i of the start_list
if this_time is greater than the current_time then
set the chapter_index to (i - 1)
exit repeat
end if
end repeat
-- CREATE NEW CHAPTER LIST
if the chapter_index is 0 then
-- THE NEW CHAPTER WILL BE THE FIRST
set the new_chapterlist to the chapter_list
set the beginning of the the new_chapterlist to the new_chapter
set the new_startlist to the start_list
set the beginning of the new_startlist to the current_time
(*======== WARNING WARNING WARNING =========*)
set the contents of the chapter_track to the new_chapterlist -------> see if you can fix this line!
(*======== THIS IS THE PROBLEM LINE ==========*)
else if the chapter_index is the chapter_count then
-- THE NEW CHAPTER WILL BE THE LAST
set the new_chapterlist to the chapter_list
set the end of the new_chapterlist to the new_chapter
set the new_startlist to the start_list
set the end of the new_startlist to the current_time
set the contents of the chapter_track to the new_chapterlist
else
set the new_chapterlist to ¬
(items 1 thru chapter_index of the chapter_list) & ¬
new_chapter & ¬
(items (chapter_index + 1) thru -1 of the chapter_list)
set the new_startlist to ¬
(items 1 thru chapter_index of the start_list) & ¬
current_time & ¬
(items (chapter_index + 1) thru -1 of the start_list)
set the contents of the chapter_track to the new_chapterlist
end if
-- APPLY PROPERTIES TO EVERY CHAPTER
set the list_count to the count of the new_chapterlist
repeat with i from 1 to the list_count
if i is the list_count then -- last chapter
set this_time to item i of the new_startlist
set the time of chapter i to this_time
set the duration of chapter i to ¬
movie_end - this_time
else
set this_time to item i of the new_startlist
set the time of chapter i to this_time
set the duration of chapter i to ¬
(item (i + 1) of the new_startlist) - this_time - 1
end if
end repeat
end tell
on error error_message number error_number
if the error_number is not -128 then
beep
display dialog error_message buttons {"Cancel"} default button 1
end if
end try
end tell
It didn’t work. I get an NSUnknownKeyScriptError. I found the line in the code which causes the error… I marked it in the script above so you can see it. I tried everything I could think of to fix the problem but couldn’t. CAN YOU FIX THIS???