The issue here is that 'sword' in this case is just a projectile which looks like a sword, like an enemy's version of sword beams (place a lynel or L2 Stalfos down if you need to see it).
You can use this script, however. Haven't tested it, but it's got no reviews saying that it doesn't work etc, so it's probably fine.