Yes, you need to authorise your application to control System Events. It's under Accessibility of System Preferences.
System Events
For more information, see the wiki Searching the Forum for Answers section.