-- -- 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) -- Last updated: 07 May 2023 -- 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) --display dialog "fixSrt: " & theFolder tell application "Finder" set movieFiles to get every file of folder (theFolder) whose name extension is in {"mp4", "mpg", "mkv", "avi"} repeat with theFile in movieFiles local srtFile, srtFiles, srtName, theFileName 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" -- find "X_English.srt" in the "Subs" folder before looking for srt files in the movie's folder try local subsFolder set subsFolder to (first folder whose name starts with "Sub") of folder theFolder set srtFiles to (every file of subsFolder whose (name ends with "English.srt" or name ends with "Eng.srt") and size > 5000) if (count of srtFiles) is 0 then set subsFolder to (first folder whose name is theFileName) of subsFolder set srtFiles to (every file of subsFolder whose (name ends with "English.srt" or name ends with "Eng.srt") and size > 5000) end if on error return null end try if (count of srtFiles) is 0 then -- nothing in Subs folder - check the top folder now 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 display dialog "Cannot identify an English srt file" giving up after 5 return null end if 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) set name of srtFile to srtName end repeat end tell return "ok" end fixSrt on open theDroppedItems repeat with theItem in theDroppedItems try my fixSrt(theItem) on error -- ignore end try 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