Skip to content

Instantly share code, notes, and snippets.

@milnak
Created April 3, 2025 23:30
Show Gist options
  • Save milnak/0b2ece756062b00cca408d27b4fdee13 to your computer and use it in GitHub Desktop.
Save milnak/0b2ece756062b00cca408d27b4fdee13 to your computer and use it in GitHub Desktop.
Batch convert folder of MuseScore MSCZ files to PDF
Get-ChildItem -File -Filter '*.mscz' | ForEach-Object {
"Converting $($_.BaseName) ..."
$tempfile = 'temp.json'
'* Extract JSON'
Start-Process `
-Wait `
-WorkingDirectory (Get-Location).Path `
-FilePath """$env:ProgramFiles\MuseScore 4\bin\MuseScore4.exe""" `
-ArgumentList '--score-parts-pdf', ('"{0}"' -f $_.FullName), '--export-to', $tempfile
$json = Get-Content $tempfile | ConvertFrom-Json
$name = Split-Path -LeafBase $json.score
$filename = $name + $json.scoreFullPostfix
"* Extracting score $name"
Set-Content -LiteralPath $filename -AsByteStream -Value ([Convert]::FromBase64String($json.scoreBin))
for ($i = 0; $i -lt $json.parts.Count; $i++) {
$partname = $json.parts[$i]
"* Extracting part $partname"
$filename = '{0}-{1}.pdf' -f (Split-Path -LeafBase $name), $partname
Set-Content -LiteralPath $filename -AsByteStream -Value ([Convert]::FromBase64String($json.partsBin[$i]))
}
'* Remove JSON'
Remove-Item $tempfile
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment