this is the apple script I use to convert native lightburn GRBL g-code to code that my Mach3 unit can use.
This requires that you have M11Px and M10 set up and working within Mach3. The script adds M11Px and M10 to the GRBL g-code at every G0 move. This is also set up with Mac and probably will not work on Windows machines. If youβd like to use my work and create a windows based version please feel free.
This allows me to control laser power and get synchronized on/off without any delay while still using Mach 3. Unfortunately Iβm not able to upload the file so here is the text version.
β Choose the file to be modified using the Finder
set chosenFile to choose file with prompt βChoose a file to modify:β
set fileReference to open for access chosenFile with write permission
β Initialize variables
set modifiedLines to {}
β Define the text to be inserted
set insertLineAbove to βM10P2β
set insertLineBelow to βM11P2 Sβ
β Read and process the file line by line
try
β Read the file line by line
set eofReached to false
repeat until eofReached
try
β Read the current line
set currentLine to read fileReference until linefeed
β Check if the line contains βG0β
if currentLine contains βG0β then
β Add M10P2 one line above the G0 command
set end of modifiedLines to insertLineAbove
set end of modifiedLines to currentLine
β Add M11P2 S25 one line below the G0 command
set end of modifiedLines to insertLineBelow
else
β Keep the line unchanged
set end of modifiedLines to currentLine
end if
on error
β End of file reached
set eofReached to true
end try
end repeat
β Close the file for reading
close access fileReference
β Add M30 at the end of the modified lines
set end of modifiedLines to βM30β
β Combine the modified lines into a single string with line breaks
set modifiedText to (modifiedLines as text)
β Write the modified text back to the file
set fileReference to open for access chosenFile with write permission
set eof of fileReference to 0
write modifiedText to fileReference
close access fileReference
display dialog βFile successfully modified and saved.β buttons {βOKβ} default button βOKβ
on error errMsg
β Handle any errors that occur
try
close access fileReference
end try
display dialog "Error: " & errMsg buttons {βOKβ} default button βOKβ
end try
I have a second version of this that I have not yet tested that eliminates the Sx command after the M11Px command. Iβm hoping this version will just read the S command from the code and respond accordingly. Unfortunately Iβm away from my machine this weekend and will not be able to test this until next week. If this works I may be able to do some raster engraving. Iβll post again next week if I am successful.