MS4 - Batch Processing - MusicXML parts

• May 21, 2025 - 15:31

I posted this yesterday and got no traction. Maybe I had the wrong section (or this is just too niche). Anyways:

I successfully made a script with the help of ChatGPT that exports the MIDI file and MusicXML file for all files in a folder. I will attach it to this thread as a txt file instead of ".sh". For the life of me, ChatGPT, and Gemini, "we" cannot figure out how to export the Piano part for the MusicXML. Fairly certain I am not messing up on this. Is this not possible with the command line?

Attachment Size
export_musescore copy.txt 1008 bytes

Comments

I don't use command prompt scripts at all, but the way to bet is that ChatGPT's contribution is wrong, and probably even nonsensical.

In reply to by TheHutch

Certainly possible. I was pleasantly surprised it help me create the script that batch exported MIDI and XML's correctly. I am not a programmer by any means. I have dabbled with command line/terminal briefly but not my area of expertise. From what I have gathered, it seems to be a limit of Musescore API. But, I (or ChatGPT) could be wrong....

In reply to by Josh Mills

Well... nor sure an AI can do that, here's my NI attempt at it ;-)

#!/bin/bash
 
# === CONFIGURATION ===
SOURCE_DIR="$HOME/Desktop/Source"
MUSESCORE_APP="/Applications/MuseScore 4.app/Contents/MacOS/mscore"
 
# === FIND VALID MSCZ FILES ===
files=("$SOURCE_DIR"/*.mscz)
total=${#files[@]}
count=0
 
# === EXIT IF NO FILES FOUND ===
if [ $total -eq 0 ]; then
    echo "⚠️ No .mscz files found in $SOURCE_DIR"
    exit 1
fi
 
# === EXPORT LOOP ===
echo "🔄 Exporting $total files to MIDI and MusicXML..."
 
echo "[" > job.json # start JSON file
 
for file in "${files[@]}"; do
    # Skip if file doesn't exist or is autosave
    [[ -f "$file" && "$file" != *",.mscz" ]] || continue
 
    BASENAME=$(basename "$file" .mscz)
 
    echo "{ \"in\": \"$file\"," >>  job.json # add input file to JSON file
    echo " \"out\": [ \"$SOURCE_DIR/$BASENAME.mid\", \"$SOURCE_DIR/$BASENAME.musicxml\" ] }," >>  job.json # add output files to JSON file
    # Update progress bar
    ((count++))
    percent=$((count * 100 / total))
    echo -ne "Progress: $count/$total [$percent%]\r"
done
 
echo "{}" >> job.json # fixup JSON file (workaround tor a trailing comma not being allowed)
echo "]" >> job.json # finalize JSON file
 
# Export MIDI and MusicXML (suppressing QML output)
"$MUSESCORE_APP" -j job.json 2>/dev/null
 
rm job.json # cleaunp JSON file
 
echo -e "\n✅ All done. Exported to: $SOURCE_DIR"

Entirely untested ;-)

In reply to by Jojo-Schmitz

Thank you SO much for this! I tried running this in my Shortcuts Mac app but it didn't work. I hate to bother you, but is this relying on me to make a JSON file in addition? My assumption is that this would just get run as a shell script and it would do everything. I briefly looked at the code and didn't glean much from it. Sorry 😬

In reply to by Jojo-Schmitz

I did the first step but did not see a JSON file in the Source folder.

I did the second step and got the same output as before I believe:
🔄 Exporting 8 files to MIDI and MusicXML...
Progress: 1/8 [12%]
Progress: 2/8 [25%]
Progress: 3/8 [37%]
Progress: 4/8 [50%]
Progress: 5/8 [62%]
Progress: 6/8 [75%]
Progress: 7/8 [87%]
Progress: 8/8 [100%]
✅ All done. Exported to: /Users/millsj1134/Desktop/Source

In reply to by Jojo-Schmitz

Yeah, I have been seeing that I think I did this wrong. I used ChatGPT and think I figured out how to do what you asked. Here's the JSON file. Note: it is exporting the full score MIDI and Full Score MusicXML, but I would like it to only export the "Piano" part for the MusicXML. Not sure if that is possible.

Sorry about my lack of knowledge. This is way out of my domain lol 😂 I appreciate your patience. Trying my best!

PS: is "NI" for "Natural Intelligence"? lol 😂 I realized that a way after initially reading that this morning. 😀😀

Attachment Size
job.json_.zip 469 bytes

In reply to by Jojo-Schmitz

Unfortunately I think that's what is causing the issue. The new updated code with your two modifications exports MIDI and MusicXML which is awesome (and shows I had human error 😬) but what I Really would love is the ability to choose which part gets exported for the MusicXML. I wonder if this would be beneficial for anyone else other than me? Could be in very edge case water here... hahahaha

Do you still have an unanswered question? Please log in first to post your question.