System Events
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')
se.keystroke('Hello')
se.keystroke('a', { using: 'command down' })
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)
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"])
- Foreword
- Conventions Used in This Cookbook
- Using JavaScript for Automation
- ES6 Features in JXA
- Getting the Application Instance
- User Interactions
- User Interaction with Files and Folders
- Using Objective-C (ObjC) with JXA
- Shell and CLI Interactions
- Importing Scripts
- iTunes
- Keynote
- Messages
- System Events
- Safari & Chrome
- Script Editor
- XML
- Examples