Here's a script to make the .SM files in a folder read-only (both the file-system attribute and SMath attribute)
It's actually two scripts, the .bat file calls the .vbs and they must be in the same folder. I'm sure it could be done from one .vbs but I didn't want to take the time.
Usage: MakeAllSMfilesReadOnly <folder>
where <folder> is the full path and name of the folder containing the .sm files to make read-only
I assigned a right-click Send To command shortcut to it so I can just right-click the folder and Send to, Make SM files read only.
In case I cannot attach the files the code is also included below. Code is between separators ===...
MakeAllSMfilesReadOnly.bat
===========================================
@echo off
:: This script makes an SMath file read-only by adding the string <editable>false</editable>
:: to the <settings> section. This is the same as File, Properties, File Attributes, Read-only in SMath
Title=Make all SMath files in folder %1 read-only...
set spath=%~dp0
:: Might need to uncomment below for older systems
rem setlocal EnableExtensions
set ATTR=%~a1
set DIRATTR=%ATTR:~0,1%
rem endlocal
:: If %1 is a folder then continue
if /i "%DIRATTR%"=="d" (
echo.
echo Are you sure? [read title of this window - Ctrl-C to cancel]
echo.
pause
%~d1
cd %1
setlocal EnableDelayedExpansion
for /f "delims=|" %%i IN ('dir /b %1\*.sm'
DO (
set smfile="%%i"
echo.
echo Processing file [ %%i ]...
echo.
For /F "Delims=" %%j In ('Attrib !smfile!'
Do Set _Attribs=%%j
:: Remove read-only attribute, if set
If "!_Attribs:~5,1!"=="R" Attrib -R !smfile!
cscript "%spath%read-only-sm-file.vbs" !smfile!
:: Set read-only attribute
Attrib +R !smfile!
)
endlocal
) else (
echo.
echo %1 is NOT a folder
echo.
)
pause
:EOF
===========================================
read-only-sm-file.vbs
===========================================
' Modify SMath .sm file to make it read-only
Const ForReading = 1
Const ForWriting = 2
strFileName = Wscript.Arguments(0)
strOldText = "<settings>" & vbCrLf & " <identity>"
strNewText = "<settings>" & vbCrLf & " <editable>false</editable>" & vbCrLf & " <identity>"
On Error Resume Next
lngCount = Wscript.Arguments(3)
If Err.Number <> 0 Then lngCount = -1
On Error Goto 0
Set objFSO = CreateObject("Scripting.FileSystemObject"
Set objFile = objFSO.OpenTextFile(strFileName, ForReading)
strText = objFile.ReadAll
objFile.Close
If Instr(1, strText, strOldText) > 0 Then
strNewText = Replace(strText, strOldText, strNewText, 1, lngCount)
Set objFile = objFSO.OpenTextFile(strFileName, ForWriting)
objFile.Write strNewText 'WriteLine adds extra CR/LF
objFile.Close
End If
===========================================