-- -- Fix_subtitles should be opened in "Script Editor.app" on a Mac and then -- you can either hit Run (cmd-R) or use "Save As" from the "File" menu and -- save it as an application (uncheck both Options). -- -- If you run it, you get to choose the folder in which there's a movie -- file an a Subs folder with multiple subtitles. It attempts to choose a -- large enough "_Eng.sub" or "_English.sub" file and copies it to the -- parent folder, then renames it to match the movie file's name. -- You can also drop the folders with movies inside onto the saved app, -- Or set this program to be run when Transmission.app has finished a download, -- to have the subtitles copies automatically. -- -- Written 2020 by Thomas Tempelmann (tempelmann@gmail.com) -- Original file: http://files.tempel.org/Various/Fix_subtitles.applescript -- -- You may share this script with others as long as you keep all of this -- note inside. Be nice and enjoy! use AppleScript version "2.4" -- Yosemite (10.10) or later use scripting additions on fixSrt(theFolder) tell application "Finder" set movieFiles to get every file of folder (theFolder) whose name extension is in {"mp4", "mpg", "mkv", "avi"} if (count of movieFiles) is not 1 then display dialog "Cannot identify a single movie file" giving up after 5 return movieFiles end if set theFile to first item of movieFiles set theFileName to name of theFile set theFileName to text 1 thru ((theFileName's length) - (offset of "." in  (the reverse of every character of theFileName) as text)) of theFileName set srtName to theFileName & ".srt" local srtFile set srtFiles to get every file of folder (theFolder) whose name extension is "srt" if (count of srtFiles) = 1 then set srtFile to first item of srtFiles if name of srtFile is srtName then return "already done" end if else -- find "X_English.srt" in the "Subs" folder try set srtFiles to (every file of folder "Subs" of folder theFolder whose (name ends with "_English.srt" or name ends with "_Eng.srt") and size > 5000) on error return null end try if (count of srtFiles) is 0 then display dialog "Cannot identify an English srt file" giving up after 5 return null end if set srtFile to first item of srtFiles --display dialog "Identifed srt file " & srtFile copy srtFile to folder theFolder set srtFile to (file (name of srtFile) of folder theFolder) end if set name of srtFile to srtName end tell return "ok" end fixSrt on open theDroppedItems repeat with theItem in theDroppedItems my fixSrt(theItem) end repeat end open on run -- Handle the case where the script is launched without any dropped files open (choose folder with multiple selections allowed) end run