Open the currently active file from Xcode in Cursor at the same line and column. This repo contains a small shell script you can wire up to an Xcode Behavior and trigger via a keyboard shortcut.
- Detects the active document in Xcode (the foremost window) and reads the caret position.
- Finds the nearest Xcode project root by searching up for a
.xcodeprojor.xcworkspace. - Launches Cursor on that project root and jumps straight to the file at the exact
line:column.
- macOS with Xcode 14/15/16.
- Cursor installed, with the
cursorcommand available in yourPATH.- In Cursor, run: Command Palette → “Shell Command: Install ‘cursor’ command in PATH”.
- On first run, macOS may prompt for Automation/Accessibility permissions.
- Clone or download this repo.
- Make the script executable:
chmod +x /absolute/path/to/open-in-cursor.sh
- Optional (recommended): Move or symlink it to a stable location, e.g.
~/bin/open-in-cursor.sh.
- Open Xcode → Settings… → Behaviors.
- Click the + button to create a new behavior (e.g., “Open in Cursor”).
- Assign a keyboard shortcut.
- In the behavior details, check “Run” and choose “Command…”. Point it at your
open-in-cursor.sh.
Now, when you press the shortcut in Xcode, Cursor will open the project and jump to the same cursor position.
- Save first: The script requires the file to be saved (it intentionally warns when the window title shows “Edited”).
- Multiple windows: It targets the foremost Xcode window and resolves the document by the name in the title bar.
- Project detection: If no
.xcodeproj/.xcworkspaceis found up the tree, it falls back to the file’s directory.
- “cursor: command not found”: Install the Cursor CLI from Cursor’s Command Palette, or ensure your PATH includes the Cursor binary directory. The script already adds common locations to PATH.
- “Please save the current document…”: Save the file in Xcode before triggering the behavior.
- “No matching document found” / “No Xcode window found”: Ensure the file is open and Xcode has a frontmost window.
- Nothing happens on first run: macOS may prompt for Automation permissions (Xcode/osascript controlling Xcode). Approve prompts in System Settings → Privacy & Security → Automation/Accessibility.
- Logs: Output is mirrored to Console.app with subsystem/tag
open-in-cursor. Open Console and search foropen-in-cursor.
MIT — see LICENSE.