Command-line interface for ServiceNow script synchronization via the browser extension.
The sn-scriptsync CLI allows you to sync ServiceNow scripts from the command line, enabling integration with any text editor (Vim, Emacs, Sublime, etc.) while leveraging the browser extension for authentication and communication with ServiceNow.
┌─────────────────┐ WebSocket ┌──────────────────┐
│ CLI Tool │◄────────────────────►│ Browser Ext. │
│ (Any Editor) │ Port 1978 │ (SN Utils) │
└─────────────────┘ └──────────────────┘
│ │
│ File System │ REST API
│ (Read/Write) │
▼ ▼
┌─────────────────┐ ┌──────────────────┐
│ Local Files │ │ ServiceNow │
│ ~/workspace │ │ Instance │
└─────────────────┘ └──────────────────┘
- ✅ Connect to browser extension WebSocket server
- ✅ Receive code from ServiceNow (when VSCode is not running)
- ✅ Send code changes to ServiceNow automatically
- ✅ File watcher for automatic synchronization
- ✅ Pull scope artifacts from ServiceNow
- ✅ Load instance metadata
- ✅ Open files in ServiceNow instance
- ✅ Refresh files from instance
- ✅ Works with any text editor
- Install the SN Utils browser extension
- Have a ServiceNow instance with the browser extension configured
- Node.js 16+ installed
cd cli
npm install
npm run build
npm link # Makes 'sn-scriptsync' command available globallyStart the CLI in your workspace directory:
# Navigate to your scriptsync workspace
cd ~/Documents/sn-scriptsync
# Start the CLI (connects to browser extension and watches files)
sn-scriptsync connect
# Or specify custom options
sn-scriptsync connect --port 1978 --host 127.0.0.1 --workspace /path/to/workspaceThis will:
- Connect to the browser extension WebSocket server (port 1978)
- Watch for file changes in your workspace
- Automatically sync changes to ServiceNow
- Receive new code from ServiceNow (even when VSCode is not running)
sn-scriptsync statusLoad all artifacts from your current scope:
# Basic pull
sn-scriptsync pull
# Include empty artifacts
sn-scriptsync pull --allDownload table names and properties for IntelliSense:
sn-scriptsync metadataOpen a synced file in the ServiceNow instance:
sn-scriptsync open path/to/file.script.jsPull the latest version of a file from ServiceNow:
sn-scriptsync refresh path/to/file.script.js| VSCode Extension Function | CLI Command/Feature | Description |
|---|---|---|
startServers() |
sn-scriptsync connect |
Start WebSocket client |
saveFieldAsFile() |
Automatic (via WebSocket) | Receive code from browser |
saveFieldsToServiceNow() |
Automatic (via file watcher) | Send code to ServiceNow |
saveWidget() |
Automatic (via WebSocket) | Receive widget data |
requestScopeArtifacts() |
sn-scriptsync pull |
Load scope artifacts |
requestInstanceMetaData() |
sn-scriptsync metadata |
Load instance metadata |
openInInstance() |
sn-scriptsync open <file> |
Open file in instance |
refreshFromInstance() |
sn-scriptsync refresh <file> |
Refresh file from instance |
-
Initial Setup (one-time):
# Open browser extension and run /token command # This establishes the connection # Start CLI in workspace cd ~/Documents/sn-scriptsync sn-scriptsync connect
-
Pull Existing Scripts:
# In another terminal (or before connecting) sn-scriptsync pull --all -
Edit with Your Favorite Editor:
# Use Vim, Emacs, Sublime, or any editor vim instance-name/global/sys_script/MyBusinessRule.script.js # Changes are automatically synced to ServiceNow!
-
Open in Browser (when you need to check the UI):
sn-scriptsync open instance-name/global/sys_script/MyBusinessRule.script.js
# Terminal 1: Start CLI
sn-scriptsync connect
# Terminal 2: Edit files
cd ~/Documents/sn-scriptsync/instance-name
vim global/sys_script/MyBusinessRule.script.jsEvery time you save in Vim (:w), the CLI automatically syncs to ServiceNow.
The CLI works with any editor that writes to the filesystem:
- Vim/Neovim
- Emacs
- Sublime Text
- Atom
- Nano
- Even
sedorawkscripts!
The CLI uses the same file structure as the VSCode extension:
workspace/
├── instance-name/
│ ├── settings.json # Instance configuration
│ ├── scopes.json # Scope mappings
│ ├── tablenames.d.ts # Table names for IntelliSense
│ ├── properties.d.ts # Properties for IntelliSense
│ └── scope-name/
│ ├── scope.json # Scope metadata
│ └── table-name/
│ ├── _map.json # Name to sys_id mapping
│ ├── record1.script.js
│ ├── record2.script.js
│ └── widget-name/ # For widgets
│ ├── template.html
│ ├── css.scss
│ ├── client_script.js
│ └── script.js
The CLI reads configuration from the existing instance settings created by the browser extension. No additional configuration is needed.
Make sure:
- The browser extension is installed and active
- You've run the
/tokencommand in your ServiceNow instance - The helper tab is open in your browser
- Port 1978 is not blocked by a firewall
- Check that you're in the correct workspace directory
- Verify the file follows the correct naming pattern:
name.field.extension - Check the
_map.jsonfile exists and contains the sys_id mapping
This means the file doesn't follow the expected structure or doesn't have a sys_id mapping. Pull the file from ServiceNow first using the browser extension or sn-scriptsync pull.
If you're running multiple instances:
sn-scriptsync connect --port 1979 --workspace /path/to/workspace2Integrate with shell scripts:
#!/bin/bash
# Pull latest, edit, and open in browser
sn-scriptsync pull
vim instance/global/sys_script/MyScript.script.js
sn-scriptsync open instance/global/sys_script/MyScript.script.js| Feature | VSCode Extension | CLI Tool |
|---|---|---|
| Code Sync | ✅ | ✅ |
| File Watching | ✅ | ✅ |
| Browser Communication | ✅ WebSocket Server | ✅ WebSocket Client |
| Editor | VSCode only | Any editor |
| Tree View | ✅ | ❌ (use filesystem) |
| IntelliSense | ✅ | ❌ (editor-dependent) |
| Background Scripts | ✅ | ✅ (future) |
See VIM_INTEGRATION.md for Vim-specific integration patterns and recommendations.