Osascript quoting issue

I am at a loss on this one. I am trying to run this command on a bunch of (OS 10.7.4) macs:

osascript -e "tell application \"System Events\" to return name of every process whose frontmost is true"

On some, it works fine. On others, I get this error:

I have also tried (note the single quotes):

osascript -e 'tell application "System Events" to return name of every process whose frontmost is true'

but I get the same error. What am I missing? Why does this work on some machines and not others?

You are missing a strong quote at the beginning of your statement.

osascript -e 'tell application "System Events" to return name of every process whose frontmost is true'
             ^***** 

Actually that's a typo. Sorry. It doesn't work with strong quotes either.

---------- Post updated at 02:27 PM ---------- Previous update was at 01:18 PM ----------

Ok, it looks like it just wasn't working over SSH. What I was actually trying to do was have a little background app pull commands from a mysql database and run them, but something about the formatting must get changed when pulling the command that way, because it fails to run on some machines. I ended up just storing the command within the app and it seems to work fine.

The following forms work for me (local machine running 10.8.1, remote machine running 10.5.8):

ssh MYSERVERNAME "osascript -e 'tell application \"System Events\" to return name of every process whose frontmost is true'"

ssh MYSERVERNAME 'osascript -e "tell application \"System Events\" to return name of every process whose frontmost is true"'