Skip to content

Instantly share code, notes, and snippets.

@alexeypegov
Created September 4, 2010 17:18
Show Gist options
  • Save alexeypegov/565328 to your computer and use it in GitHub Desktop.
Save alexeypegov/565328 to your computer and use it in GitHub Desktop.
Convert AVI files to M4V (iPhone) one by one using QuickTime Player X
--
-- simple AppleScript to convert chosen AVI files to iPhone video format one by one using QuickTime Player X
--
property outputFolder : (path to movies folder as Unicode text)
on check_exists(fileToCheck)
repeat
tell application "Finder"
if exists file fileToCheck then
exit repeat
end if
end tell
delay 5
end repeat
end check_exists
on export_files(theFiles)
repeat with currentFile in theFiles
set AppleScript's text item delimiters to ":"
set filePath to (currentFile as string)
set _fileName to (text item -1 of filePath)
set AppleScript's text item delimiters to "."
set fileName to (text items 1 through -2 of _fileName) as string
set fileExt to (text item -1 of _fileName) as string
if (fileExt is equal to "AVI") then
set shouldCheck to yes
tell application "QuickTime Player"
open filePath
set exportFile to (outputFolder & fileName & " (iPhone).m4v")
try
export front document in (exportFile) using settings preset "iPhone"
on error errorMsg number errorNum
display dialog "Error (" & errorNum & "):" & return & return & errorMsg buttons "OK" default button 1 with icon caution
set shouldCheck to no
end try
close front document
end tell
if shouldCheck is yes then
check_exists(exportFile as Unicode text)
tell application "iTunes"
add (exportFile as alias)
end tell
end if
end if
end repeat
tell application "QuickTime Player" to quit
end export_files
export_files(choose file multiple selections allowed yes)
on open theFiles
export_files(theFiles)
end open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment