Skip to content

pavliuko/cursor-behavior-for-xcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

cursor-behavior-for-xcode

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.

What it does

  • 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 .xcodeproj or .xcworkspace.
  • Launches Cursor on that project root and jumps straight to the file at the exact line:column.

Requirements

  • macOS with Xcode 14/15/16.
  • Cursor installed, with the cursor command available in your PATH.
    • In Cursor, run: Command Palette → “Shell Command: Install ‘cursor’ command in PATH”.
  • On first run, macOS may prompt for Automation/Accessibility permissions.

Install

  1. Clone or download this repo.
  2. Make the script executable:
chmod +x /absolute/path/to/open-in-cursor.sh
  1. Optional (recommended): Move or symlink it to a stable location, e.g. ~/bin/open-in-cursor.sh.

Configure Xcode Behavior (keyboard shortcut)

  1. Open Xcode → Settings… → Behaviors.
  2. Click the + button to create a new behavior (e.g., “Open in Cursor”).
  3. Assign a keyboard shortcut.
  4. 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.

Usage notes

  • 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/.xcworkspace is found up the tree, it falls back to the file’s directory.

Troubleshooting

  • “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 for open-in-cursor.

License

MIT — see LICENSE.

About

Xcode behavior that opens Cursor just in the right place

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages