You can test for the correct file in PLC script. You can't put it in a buttons script because all of it's events would have already ran (pretty sure but didn't test to be honest). If there is a Gcoded loaded signal you might be able to make it a function and run it when that singlas state changes. Would be a better place than the PLC script but I didn't take time to look for or test that either.
Below is a script to do what you want. It looks for the string "Test" beginning at the second and ending at the 5 position on line 0 (Very first line of Gcode). The reason it starts a the second position is the first will be a ; or (.
Anyway, place the script in the PLC script after the inst variable is defined. Add the line "(Test)" (minus quotes) as the very first line of your Gcode and play with it. Once you are comfortable with it you can comment out the line writing to the error label and uncomment the line that pops up a message box.
local curGcode, rc = mc.mcCntlGetGcodeFileName(inst)
if (curGcode ~= lastGcode) then -- Gcode files changed
lastGcode = curGcode
if (curGcode ~= "") then --A gcode file is loaded
--mc.mcCntlSetLastError(inst, "curGcode (" .. curGcode .. ")")
local buff, rc = mc.mcCntlGetGcodeLine(inst, 0)
local s,e = string.find (buff, "Test")
if (s ~= 2) or (e ~= 5) then --The start and/or end of the unique identifier is not in the right place or it doesn't exist
local rc = mc.mcCntlCloseGCodeFile(inst)
mc.mcCntlSetLastError(inst, "File closed due to incorrect format " .. buff)
--wx.wxMessageBox("File closed due to incorrect format " .. buff)
end
end
end