Reading and writing from a file

• Jun 23, 2025 - 14:51

I'm working on a project where I need to read .mcsz or .xml files and copy them into an existing score. According the API documentation, readScore() reads a score from file but opens it in a new tab, and read() reads file contents and returns a string.
readScore won't work because I need to copy it into an existing file, and there is no information on what read() returns.
I am on Musescore 4 so I can't debug using the plugin creator.

Is there a workaround to this? I am thinking reading the xml file as plain text and somehow parsing it.


Comments

I don't think that readScore() and writeScore() are available yet in the MS4 plugin api. In MS3 you can readScore into a new tab, writeScore it out to a different file, then close the new tab.

file.read() reads an entire file into a variable and you can process it however you like. If it's a human readable text format then you can treat the variable as text. (I wouldn't recommend trying to process non-text files).

I think that javascript xml parsing libraries are available.

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