Tilt invert

I am trying to write a tilt invert macro (and also one for pan invert obviously), preferably one that toggles the state of the Tilt attribute. I somehow cannot get it to work, even if I learn the macro. Background or Foreground does not seem to matter.

I want to use select last.

Someone with a smart idea?