Close current Safari tab using Javascript?

You could trigger the macro remotely using the remote trigger option.

Then just use the get contents of URL action. No need to open Safari.

Now there are caveats to its use that are covered in the Keyboard Maestro wiki article linked above.

An alternative, and my preference, would be to use SSH (and potentially a VPN connection too) to get a really secure connection into your machine and trigger the macro that way.

This was discussed on the forum back in January and includes a brief write-up on how to implement an SSH-based approach.