My truck is dead. I think the battery is fine. It will not crank. This happened last month. While turning the key in neutral and moving the gearshift it started.
At lunch today it did it again and it won’t start at all. Is this neutral safety switch that has gone bad?
That's a logical conclusion since you observed it would start in neutral. The sliding contact inside the neutral safety switch is likely worn down or arced enough times to burn the contacts. You can start the diagnostics right at the starter relay under the hood. There's two ways to approach this.
You can pop the cover off the relay, then squeeze the movable contact. The system can be broken down into three circuits; the low-current ignition switch circuit, the medium-current starter solenoid circuit, and the high-current starter motor circuit. If the starter cranks the engine when you squeeze the movable contact, the medium and high-current circuits are working. That leaves the low-current circuit with the ignition switch and neutral safety switch with the problem.
GM used various configurations of the low-current circuit. Testing can be done at the relay socket with a test light. Ground the test light's clip lead to the battery negative post or a paint-free point on the engine, then unplug the relay and probe the four socket terminals. One will have 12 volts all the time. That will be one of the two fatter wires. A second terminal, (with a skinnier wire), must have 12 volts when a helper turns the ignition switch to "crank". If you find that, the ignition switch is okay. If you do not find 12 volts, the neutral safety switch might be in that same circuit and the cause could be either switch.
If both of those have 12 volts at the right time, move the test light's ground wire to the battery's positive post. Now we'll be checking for a good circuit to ground. Probe the two remaining terminals in the socket. The fatter wire should turn on the test light all the time. That's reading continuity through the starter solenoid. The last one should also read continuity but it should go to "open circuit", (test light goes off), when you shift out of park or neutral. If it does, the neutral safety switch is in that circuit and it's working, at least right now. Remember, this is an intermittent problem. If you find two wires that always are grounded, and the test light always lights up on them, the neutral safety switch is not in that circuit; it's in the same one as the ignition switch. In that case, going back to the tests on the first two wires with the clip lead on the negative battery post, the test light should light up on the smaller wire only when the ignition switch is turned to "crank" AND the shifter is in park or neutral.
If you find the switch to be the cause of the problem, you'll have to answer a bunch of questions at the auto parts store to get the right one. It depends on which transmission you have. Some are on the steering column and some are on the transmission.