I have a custom sync script for Firefox because the built-in sync is simply not thorough enough. To make the sync more reliable I wanted to close Firefox when it is running. This was surprisingly hard to accomplish, but once I found
wmctrl the problem was solved.
Notice that this can fail if Firefox is displaying a different window, like an http auth prompt, or if a screensaver is active.
wmctrl -c "Firefox"