Overview
Xcode Shortcuts allow you to execute custom commands directly from Xcode using the cmd extension. You can create shortcuts that open files in external editors, run scripts, or perform any command-line operation using context from your current Xcode session.Shortcuts are only available when a file is open in Xcode.
Prerequisites
Before configuring shortcuts, ensure you have granted the Xcode Extension permission:Grant Xcode Extension Permission
Follow the installation guide to enable the Xcode Source Editor extension
Creating a Shortcut
Configure the Command
Enter your command using any of the available variablesExample Commands:
This opens the current file in VS Code, jumping to the selected line if available.
Copies the current file path to your clipboard.
Executes a custom script with the selected text and file path.
Opens a new Terminal window at your project directory.
Open file in VS Code at line number
Open file in VS Code at line number
Copy file path to clipboard
Copy file path to clipboard
Run a script with context
Run a script with context
Open terminal at project location
Open terminal at project location
Lint current file
Lint current file
Name Your Shortcut
Give your shortcut a descriptive name that will appear in Xcode’s menu (e.g., “Open in VS Code”, “Copy File Path”)
Setting Up Key Bindings in Xcode
For quick access, it is recommended to assign keyboard shortcuts to your commands:(Optional) Resolve conflict
If your desired key binding conflicts with one already defined in Xcode (there’s a lot!), change or remove the conflicting one.
Variable Reference
Use these variables in your shortcut commands to access Xcode context:| Variable | Description | Example Value |
|---|---|---|
$FILEPATH | Absolute path to the current file | /Users/name/project/ContentView.swift |
$FILEPATH_FROM_GIT_ROOT | Relative path to the current file from the git root | ./project/ContentView.swift |
$SELECTED_LINE_NUMBER_START | First line of selection | 42 |
$SELECTED_LINE_NUMBER_END | Last line of selection | 58 |
$XCODE_PROJECT_PATH | The path to the project active in Xcode | /Users/name/swift-package /Users/name/app.xcodeproj |

