The QuickTimePro script “Save Current Frame as JPEG” works fine on .mov, but fails on .avi.
This is an supplied QuickTime Pro script. Any ideas why? I assume I could save the avi as a .mov, but would rather simplify. A single frame movie is created, the failure is with final saving. I thought maybe there was some “illegal” or confusing character in my file name, but it fails for the same when named test.avi. The problem is in the naming of the temp files which I don’t understand, but will explore further.
At the risk of posting a long question here are the details:
Event log with avi:
tell application "QuickTime Player"
activate
exists movie 1
true
stop every movie
get QuickTime version
7.1
get version
"7.1.3"
get QuickTime Pro installed
true
choose file name with prompt "Name & location for the saved frame:" default name "image.jpg"
file "Tiger iMac HD:Users:gscar:Documents:â—Š Pre-trash:Photo saving scripts:image.jpg"
activate
display dialog "Extracting the current frame." buttons {"¢"} default button 1 giving up after 2
{button returned:"", gave up:true}
get current time of movie 1
1761
select none movie 1
copy movie 1
make new movie
document "Untitled 2"
paste movie 1
activate
display dialog "Creating temp folder." buttons {"¢"} default button 1 giving up after 2
{button returned:"", gave up:true}
random number from 100000 to 999999
323033
end tell
tell application "Finder"
exists folder "323033" of desktop
false
make new folder at desktop with properties {name:"323033"}
folder "323033" of folder "Desktop" of folder "gscar" of folder "Users" of startup disk
get folder "323033" of folder "Desktop" of folder "gscar" of folder "Users" of startup disk
alias "Tiger iMac HD:Users:gscar:Desktop:323033:"
end tell
tell application "QuickTime Player"
activate
display dialog "Exporting frame image as JPEG." buttons {"¢"} default button 1 giving up after 2
{button returned:"", gave up:true}
export movie 1 to file "Tiger iMac HD:Users:gscar:Desktop:323033:TEMP_IMAGE" as image sequence using settings preset "JPEG, 25 fps"
close movie 1 saving no
end tell
tell application "Finder"
set name of file 1 of alias "Tiger iMac HD:Users:gscar:Desktop:323033:" whose name ends with "1.jpg" to "image.jpg"
end tell
tell application "QuickTime Player"
beep
display dialog "Finder got an error: Can't set name of file 1 of alias \"Tiger iMac HD:Users:gscar:Desktop:323033:\" whose name ends with \"1.jpg\" to \"image.jpg\"." buttons {"Cancel"} default button 1
"QuickTime Player got an error: User canceled."
Event log for .mov:
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
set the new_file to choose file name with prompt "Name & location for the saved frame:" default name "image.jpg"
set AppleScript's text item delimiters to ":"
set the new_name to the last text item of (the new_file as string)
set the destination_folder to ((text items 1 thru -2 of (the new_file as string)) as string) & ":"
set AppleScript's text item delimiters to ""
my status_dialog("Extracting the current frame.")
set the current_time to current time of movie 1
select none of movie 1
copy movie 1
make new movie
paste movie 1
my status_dialog("Creating temp folder.")
-- create a unique temp folder
repeat
set this_name to (random number from 100000 to 999999) as string
tell application "Finder"
if not (exists folder this_name of the desktop) then
set the temp_folder to (make new folder at desktop with properties {name:this_name}) as alias
exit repeat
end if
end tell
end repeat
my status_dialog("Exporting frame image as JPEG.")
set the tempfile_name to "TEMP_IMAGE"
set the target_file to ((temp_folder as string) & tempfile_name)
-- export the image as a JPEG
export movie 1 to file target_file as image sequence using settings preset "JPEG, 25 fps"
close movie 1 saving no
tell application "Finder"
--rename the image and move it to the desktop or other folder
set (the name of the first file of the temp_folder whose name ends with "1.jpg") to the new_name
move file new_name of the temp_folder to folder destination_folder with replacing
end tell
my status_dialog("Deleting the temp files.")
tell application "Finder"
-- delete the temp folder and its contents
delete temp_folder
-- empty trash -- GVS change
end tell
display dialog "Done." buttons {"Show File", "OK"} default button 2
if the button returned of the result is "Show File" then
tell application "Finder"
activate
reveal the new_file
end tell
end if
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
on status_dialog(this_message)
tell application "QuickTime Player"
activate
display dialog this_message buttons {"¢"} default button 1 giving up after 2
end tell
end status_dialog
The script:
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
set the new_file to choose file name with prompt "Name & location for the saved frame:" default name "image.jpg"
set AppleScript's text item delimiters to ":"
set the new_name to the last text item of (the new_file as string)
set the destination_folder to ((text items 1 thru -2 of (the new_file as string)) as string) & ":"
set AppleScript's text item delimiters to ""
my status_dialog("Extracting the current frame.")
set the current_time to current time of movie 1
select none of movie 1
copy movie 1
make new movie
paste movie 1
my status_dialog("Creating temp folder.")
-- create a unique temp folder
repeat
set this_name to (random number from 100000 to 999999) as string
tell application "Finder"
if not (exists folder this_name of the desktop) then
set the temp_folder to (make new folder at desktop with properties {name:this_name}) as alias
exit repeat
end if
end tell
end repeat
my status_dialog("Exporting frame image as JPEG.")
set the tempfile_name to "TEMP_IMAGE"
set the target_file to ((temp_folder as string) & tempfile_name)
-- export the image as a JPEG
export movie 1 to file target_file as image sequence using settings preset "JPEG, 25 fps"
close movie 1 saving no
tell application "Finder"
--rename the image and move it to the desktop or other folder
set (the name of the first file of the temp_folder whose name ends with "1.jpg") to the new_name
move file new_name of the temp_folder to folder destination_folder with replacing
end tell
my status_dialog("Deleting the temp files.")
tell application "Finder"
-- delete the temp folder and its contents
delete temp_folder
-- empty trash -- GVS change
end tell
display dialog "Done." buttons {"Show File", "OK"} default button 2
if the button returned of the result is "Show File" then
tell application "Finder"
activate
reveal the new_file
end tell
end if
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
on status_dialog(this_message)
tell application "QuickTime Player"
activate
display dialog this_message buttons {"¢"} default button 1 giving up after 2
end tell
end status_dialog