Skip to content
dtinth edited this page Nov 12, 2014 · 25 revisions

The System Events application lets you automate the GUI in any application. You can see some examples in AppleScript Wikibook.

var se = Application('System Events')

Sending Keystrokes

se.keystroke('Hello')
se.keystroke('a', { using: 'command down' })

Start the Screen Saver

AppleScript Equivalent: tell application "System Events" to start the current screen saver

However, the verb here is start, and the current screen saver is the noun. So converting that to JavaScript-speak makes it look like this:

se.start(se.currentScreenSaver)

Network: Connecting to a VPN or Other Network Service

Assuming you have a VPN service called "MyVPN" in the network preferences. You can use JXA to tell your computer to connect to it.

AppleScript Equivalent: tell application "System Events" to disconnect service "MyVPN" of network preferences

se.connect(se.networkPreferences.services["MyVPN"])