set path2source to choose folder with prompt "Select your folder" default location (path to desktop)
set path2list to choose file with prompt "Select your textList" of type {"txt"}
set theList to paragraphs of (read path2list)
tell
Model: mac mini 2011
AppleScript: 2.6.1
Browser: Safari 537.36
Operating System: macOS 10.9
I have an executable UNIX file mkvpropedit inside the bundle of MKVToolNix-32.0.0 application. So, I wrote the following script that works:
set mkvPropEdit_path to "/Applications/MKVToolNix-32.0.0.app/Contents/MacOS/mkvpropedit "
set movies_Path to choose folder with prompt "SELECT YOUR FOLDER" default location (path to desktop)
set filter_List to choose file with prompt "SELECT YOUR TEXT LIST" of type {"txt"}
set filter_List to paragraphs of (read filter_List)
tell application "System Events" to set mkv_Movies to every file of movies_Path whose name extension is "mkv"
repeat with next_Movie in mkv_Movies
tell application "System Events" to set next_Movie to POSIX path of next_Movie
set next_Movie_Name to do shell script "basename -s .mkv " & quoted form of next_Movie
if next_Movie_Name is in filter_List then
do shell script mkvPropEdit_path & next_Movie & " --tags all: -d title"
end if
end repeat
NOTE: this script works fine with basic Unix paths, but throws out an error with special characters such as space, quote, (, and ) …
I tried to apply the Quoted Form of Posix Path, but so far without success. The problem is that the developers of utility mkvpropedit did not think well of the command line. It requires names with special characters in the form:
“mkvpropedit ‘my movie(1967)’.mkv --tags all: -d title”.
That is, requires filename extеnsion outside of nested quotes.
Quoted Form of Posix Path on other side gives only following form: “mkvpropedit ‘my movie(1967).mkv’ --tags all: -d title” (which not accepts UNIX shell. Here is problem with quotation syntax)
Any help? One solution I think, is temporarily rename processed video file (potentially any of them can has difficult name), doing do shell script, then renaming back to original difficult name. Not manually, of course.
-- get path to mkvpropedit UNIX executable (is inside MKVToolNix app bundle)
set mkvPropEdit_path to "/Applications/MKVToolNix-32.0.0.app/Contents/MacOS/mkvpropedit "
-- get path to movies folder (from user)
set movies_Path to choose folder with prompt "SELECT YOUR FOLDER" default location (path to desktop)
-- get list with movies names, which need metadata removing (from user)
set filter_List to choose file with prompt "SELECT YOUR TEXT LIST" of type {"txt"}
set filter_List to paragraphs of (read filter_List)
-- get all mkv files of movies folder
tell application "System Events" to set mkv_Movies to every file of movies_Path whose name extension is "mkv"
-- convert movies folder's alias path to posix path (to use later)
set movies_Path to POSIX path of movies_Path
-- process all mkv video files in loop
repeat with next_Movie in mkv_Movies
tell application "System Events"
-- backing up original name of mkv video file (to restore later)
set temp_Name to name of next_Movie
-- converting file specifier to Posix path (to use in shell command)
set posix_Path to POSIX path of next_Movie
-- get name of file without full path and extension (to compare with list)
set next_Movie_Name to do shell script "basename -s .mkv " & quoted form of posix_Path
-- if processed file name mathches to list, then continue removing of metadata in it
if next_Movie_Name is in filter_List then
-- temporarely rename potencially difficult name of file to easy name
set name of next_Movie to "myMovie.mkv"
-- remove all metadata from file
set posix_Path to movies_Path & "myMovie.mkv"
do shell script mkvPropEdit_path & quoted form of (movies_Path & "myMovie") & ".mkv --tags all: -d title"
-- restore original name of file, when complete with metadata
set alias_Path to (POSIX file posix_Path as string) as alias
set name of alias_Path to temp_Name
end if
end tell
end repeat
I have been trying to re-purpose this script to remove meta data from all MKVs in a folder, with no txt list.
But I am getting an error message when it tries to do the “do shell script mkvPropEdit_path & posix_Path & " --tags all: -d title”"
The error is "More than one file name has been given (‘/Users/username/Desktop/Folder’ and ‘1/myMovie.mkv’.
It looks like the script cannot handle a path where there is a space in a folder name. I have a folder named “Folder 1”, where the MKV files are located. Or am I misreading this?
Any suggestions to solve this would be gratefully received.
I added quoting the folder path in the post #3. Please, try and say us if this worked for you.
I can’t find proper syntax for non-English folder and movie names… mkvpropedit tool guides on the net doesn’t provide any example with non-English movie name which can contain spaces as well…
This works for me. Note the version change in the tool.
Basically, instead of using applescript’s ‘quoted form’ it uses the shell’s escaping '' to handle spaces. Also, it reads the list file as utf-8 to better handle file names with non-latin scripts.
use scripting additions
-- get path to mkvpropedit UNIX executable (is inside MKVToolNix app bundle)
set mkvPropEdit_path to "/Applications/MKVToolNix-41.0.0.app/Contents/MacOS/mkvpropedit "
-- get path to movies folder (from user)
set movies_Path to choose folder with prompt "Select movies folder" default location (path to downloads folder)
-- get list with movies names, which need metadata removing (from user)
set filter_List to choose file with prompt "Select text list" of type {"txt"} default location (path to desktop)
-- read as utf-8 to handle more characters
set filter_List to paragraphs of (read filter_List as «class utf8»)
tell application "System Events" to set mkv_Movies to every file of movies_Path whose name extension is "mkv"
set movies_Path to POSIX path of movies_Path
-- track tag-edited movies
set shellMov to {}
repeat with next_Movie in mkv_Movies
tell application "System Events"
-- converting file specifier to Posix path (to use in shell command)
set posixPath to POSIX path of next_Movie
-- escape spaces in file names
set AppleScript's text item delimiters to space
set pp1 to text items of posixPath
set AppleScript's text item delimiters to "\\ "
set pp2 to pp1 as text
tell me to do shell script mkvPropEdit_path & pp2 & " --tags all: -d title"
set end of shellMov to name of next_Movie
end tell
end repeat
-- list tag-edited movies; if list is long, might be better to export to file
set AppleScript's text item delimiters to linefeed
-- display dialog shellMov as text
set AppleScript's text item delimiters to ""
This works for me. (I always try to get the job done with as little code as possible)
Notice the difference in the app version I am using… MKVToolNix-71.1.0.app
property mkvPropEdit : quoted form of ¬
"/Applications/MKVToolNix-71.1.0.app/Contents/MacOS/mkvpropedit"
set path2Source to quoted form of POSIX path of ¬
(choose folder with prompt "Select your folder" default location (path to desktop))
set path2List to quoted form of POSIX path of ¬
(choose file with prompt "Select your textList" of type {"txt"})
do shell script "cd " & path2Source & " ;while read line ;do " & mkvPropEdit ¬
& " \"$line\" --tags all: -d title ;done < " & path2List
If you prefer not to read the files from the list.txt, this will target all .mkv files in the chosen directory.
property mkvPropEdit : quoted form of ¬
"/Applications/MKVToolNix-71.1.0.app/Contents/MacOS/mkvpropedit"
set path2Source to quoted form of POSIX path of ¬
(choose folder with prompt "Select your folder" default location (path to desktop))
do shell script "cd " & path2Source & " ;for f in *.mkv ;do " & mkvPropEdit ¬
& " \"$f\" --tags all: -d title ;done"
I am new on the site and before I could respond on this thread (my account wasn’t validated) I had reached out to wch1zpink directly to ask a question about their code below, and to ask if there was a way that it could be amended to be able to search sub-folders as well.
I wanted to thank them here for responding so quickly with an amended code that worked perfectly. It was a very kind thing to do, and so thank you for that. The code may be useful for others and so rather than put it here myself, I would invite wch1zpink to add it in as it was their work.
@atokyo please go ahead and post my solution to you from the private message… here. I deleted all of my sent messages and no longer have the code that you asked me for.
In that case, here is the code that wch1zpink made that batch removes the title from MKV files, but will work with a folder with multiple sub-folders. Very handy!:
My current version of the app is now MKVToolNix-71.1.0.app… So make sure you edit the code to match your version. Let me know if you run into any problems.
property mkvPropEdit : quoted form of ¬
“/Applications/MKVToolNix-71.1.0.app/Contents/MacOS/mkvpropedit”
set path2Source to quoted form of POSIX path of ¬
(choose folder with prompt “Select your folder” default location (path to desktop))
do shell script “find " & path2Source & " -type f -iname "*.mkv" -mindepth 1” & ¬
" |while read line ;do " & mkvPropEdit & " "$line" --tags all: -d title ;done"
I had another thought / question… all the scripts remove the ‘title’ metadata, which is really helpful, but I also have many files where the video track, audio track, and subtitle tracks of the mkv file have odd wording in the ‘name’ section for each track.
These additional elements can be removed in the normal way using MKCToolNix, but could the script be amended to also batch remove all ‘name’ elements as well as the ‘title’ element?