property type_list : {"MooV", "MPG3", "Midi", "MPEG", "PLAY", ".SMI", "Mp3 ", "JPEG", "PICT", "TIFF", "GIFf"}
property extension_list : {"mov", "smi", "sml", "mpg", "mp3", "mid", "pict", "pct", "jpeg", "jpg", "tiff", "tif", "gif"}
global target_folder, temp_folder
on run
set AppleScript's text item delimiters to ", "
set the formats_list to type_list as string
set AppleScript's text item delimiters to ""
display dialog "Convert to QuickTime Format
This script will convert dragged-on media files in the following formats to self-contained QuickTime movies." & ¬
return & return & formats_list buttons {"OK"} default button 1
end run
-- This droplet processes both files or folders of files dropped onto the applet
on open these_items
-- this routine uses the gestaltVersion_info() sub-routine
copy my gestaltVersion_info("qtim", 8) to {QT_version, QT_string}
if the QT_version is less than "0502" then
display dialog "This script requires QuickTime 5.0.2 or higher." & ¬
return & return & "The currently installed version is: " & ¬
QT_string buttons {"Cancel"} default button 1
end if
-- 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
--set the target_folder to choose folder with prompt "Destination folder for the converted files:"
repeat with i from 1 to the count of these_items
set this_item to (item i of these_items)
set the item_info to info for this_item
if folder of the item_info is true then
process_folder(this_item)
else if (alias of the item_info is false) and ¬
((the file type of the item_info is in the type_list) or ¬
the name extension of the item_info is in the extension_list) then
process_item(this_item)
end if
end repeat
-- delete the temp folder
tell application "Finder"
delete temp_folder
empty trash
end tell
end open
-- this sub-routine processes folders
on process_folder(this_folder)
set these_items to list folder this_folder without invisibles
repeat with i from 1 to the count of these_items
set this_item to alias ((this_folder as text) & (item i of these_items))
set the item_info to info for this_item
if folder of the item_info is true then
process_folder(this_item)
else if (alias of the item_info is false) and ¬
((the file type of the item_info is in the type_list) or ¬
the name extension of the item_info is in the extension_list) then
process_item(this_item)
end if
end repeat
end process_folder
-- this sub-routine processes files
on process_item(this_item)
-- NOTE that the variable this_item is a file reference in alias format
-- FILE PROCESSING STATEMENTS GOES HERE
with timeout of 3600 seconds -- one hour per movie time limit
tell application "QuickTime Player"
launch -- bypasses promo movie
activate
my toggle_suppress(true)
stop every document
close every document saving no
try
open this_item
if saveable of document 1 is false then
error "This movie has previously been set so that it cannot be copied, edited, or saved."
end if
set the original_file to the original file of document 1
tell application "Finder"
-- set the file_name to the name of the original_file
set the file_name to my add_mov_ext(this_item)
set the target_folder to the container of the original_file
if exists file file_name of the temp_folder then ¬
delete file file_name of the temp_folder
set the new_file to ((temp_folder as text) & file_name)
end tell
save document 1 given «class dfil»:file new_file, «class savk»:self contained
tell application "Finder"
delete the original_file
move file new_file to the target_folder with replacing
empty trash
end tell
on error error_msg
try
beep
display dialog error_msg buttons {"Cancel", "Continue"} default button 2 with icon 1
on error
my toggle_suppress(false)
error number -128
end try
end try
my toggle_suppress(false)
close document 1 saving no
end tell
end timeout
end process_item
on add_mov_ext(this_item)
set the item_info to info for this_item
set the item_name to (the name of the item_info) as string
set the name_extension to (the name extension of the item_info) as string
if the name_extension is not "" then
set the base_name to (characters 1 thru -((length of name_extension) + 2) of the item_name) as string
set the new_name to the base_name & ".mov"
else
set the new_name to the item_name & ".mov"
end if
return the new_name
end add_mov_ext
on toggle_suppress(status_flag)
tell application "QuickTime Player"
set ignore auto play to the status_flag
set ignore auto present to the status_flag
end tell
end toggle_suppress
on gestaltVersion_info(gestalt_code, string_length)
try
tell application "Finder" to ¬
copy my NumToHex((system attribute gestalt_code), ¬
string_length) to {a, b, c, d}
set the numeric_version to {a, b, c, d} as string
if a is "0" then set a to ""
set the version_string to (a & b & "." & c & "." & d) as string
return {numeric_version, version_string}
on error
return {"", "unknown"}
end try
end gestaltVersion_info
on NumToHex(hexData, stringLength)
set hexString to {}
repeat with i from stringLength to 1 by -1
set hexString to ((hexData mod 16) as string) & hexString
set hexData to hexData div 16
end repeat
return (hexString as string)
end NumToHex