24

With a dark color scheme in Xcode 4 the i-beam cursor (aka text selection cursor) is nearly invisible. Is there a way to change the color of this cursor, either for Xcode specifically, or failing that, system-wide?

It'd be nice if it would automatically change to a color contrasting its background too.

5 Answers 5

47

As of Xcode 8, Apple has hidden the i-beam cursor somewhere where nobody has found it. Instead, many have chosen to use Mousecape to alter the i-beam in all programs. I prefer that method since it fixes the i-beam in other programs that support dark themes, such as Komodo editor. Mousecape should work in all Xcode versions and updating Xcode won't break the cursor. I'm currently using Mousecape in macOS 10.13.2, Xcode 9.1. Here are the steps:

  1. Download Mousecape from here
  2. Download a "cape" with modified i-beam cursor such as Bright white or Grey shadow
  3. Run Mousecape.app
  4. From Mousecape's menu bar: File > Import Cape > "cape" file downloaded above
  5. Right click imported "cape" and choose Apply
  6. Check the new cursor is working in Xcode. When satisfied, you can apply the cursor on each reboot by running a command from Mousecape's menu bar: Mousecape > Install Helper Tool
  7. Installing macOS updates (such as 10.13.1 to 10.13.2) may require repeating steps 5 and 6.

Original answer:

Xcode does NOT use the system-wide i-beam cursor as everyone I found talking about it stated as if it was a known fact. If I hadn't believed those people, I wouldn't have spent two days figuring out how to alter the system i-beam cursor by editing CoreGraphics only to find that Xcode's ibeam doesn't change. BTW, I also stumbled on how to edit other system cursors.

I spent most of a weekend figuring this out, but the i-beam cursor in Xcode CAN be edited. It's simply a TIFF file in the following location for Xcode 3.2.6 (and earlier, I assume, but have not tested):

/Developer/Library/PrivateFrameworks/XcodeEdit.framework/Versions/A/Resources/TIbeam.tiff

Xcode 4.1 has the same file but it does not affect the i-beam in the main editor (I assume it's used somewhere, but maybe not). Instead, the main editor in Xcode 4.1 uses this file:

/Developer/Library/PrivateFrameworks/DVTKit.framework/Versions/A/Resources/DVTIbeamCursor.tiff

The ibeam files have moved again in Xcode 4.4:

/Applications/Xcode.app/Contents/OtherFrameworks/XcodeEdit.framework/Versions/A/Resources/TIbeam.tiff

/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Versions/A/Resources/DVTIbeamCursor.png

/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Versions/A/Resources/[email protected]

Editing DVTIbeamCursor.png was enough to change the i-beam in the main editor on my system. On another site, someone reported that [email protected] will be used on a retina display or Apple's other new high res displays like Thunderbolt and Cinema. Who knows if TIbeam.tiff is even used anymore since they didn't update it to png.

According to comments below, in Xcode 5.0.2 all 3 cursor files were replaced with one file:

/Applications/Xcode.app/Contents/OtherFrameworks/XcodeEdit.framework/Versions/A/Resources/DVTIbeamCursor.tiff

And in 5.1.1 (boy, they sure love to change things in almost every version, don't they?):

/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Versions/A/Re‌​sources/DVTIbeamCursor.tiff

I'm guessing that file is a double resolution (aka retina display) cursor that's scaled down for non-retina screens.

If you can't find the ibeam file in your Xcode, try running this command in Terminal:

sudo find / -name 'Ibeam' -print

In Xcode 7.3, the cursor was moved inside the following bundle file so the search command above won't find it:

/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Resources/Assets.car

I recommend using a process found here to patch a new cursor into the bundle file. If you don't like the cursor it installs (I felt it was still too dark and the grey outlines blend in with grey comment text), follow these steps:

  1. Download the latest release of Theme Engine (I successfully used version 1.0.0(111) with Xcode 7.3.1)
  2. Back up /Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Versions/A/Resources/Assets.car
  3. Copy Assets.car somewhere where it can be edited, such as to ~/Documents/Assets.car.
  4. Run Theme Engine.app, click Open Document, then open ~/Documents/Assets.car.
  5. Scroll down the list of items on the left and pick DVTIbeamCursor.
  6. You should see a normal resolution and double resolution ibeam cursor image in the center panel. Drag your own ibeam image on top of either cursor and it should change to show your image. I used a PNG image.
  7. Save, then close Theme Engine.
  8. Move your modified Assets.car back to /Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Versions/A/Resources/Assets.car and keep a backup copy of your modified version somewhere so you don't have to do this again until a new Xcode version changes what's in Assets.car.

You may also wish to send an angry letter to Apple to complain that they have not fixed this problem in the last 7+ years and have instead made it progressively more difficult for users to patch Apple's broken cursor.

Don't forget to keep backups of your edited cursors. Newer Xcode versions will overwrite your custom cursors with default ones when it does a software update.

Here's the ibeam cursor I use: In png format Right click the ibeam and choose to save the image to get the png version, or click here to download the tiff version.

If you're making your own cursor, notice that where the black lines intersect in the original cursor is where the white lines intersect in my cursor. That's because the original cursor was meant to be used on a white background, so its black part is where the cursor hotspot is.

10
  • 5
    Welcome to Stack Overflow, great first answer. I verified that this works, but my DVTIbeamCursor.tiff file was in a different location, probably due to having installed it through the App Store. I found it here: /Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Versions/A/Resources/DVTIbeamCursor.tiff. Can you edit your answer to include that path too?
    – phloopy
    Aug 20, 2012 at 18:26
  • great! this makes me want to customize the begeezes out of my mac. Can I just replace any of the pngs with my own custom png and it will replace it and work? Sep 1, 2012 at 3:57
  • Yep, just replace them and it works. I've only tried doing so when XCode is not running, and I'm sure you'll have to restart XCode to get them working. Also, I've heard the newer XCodes will replace your custom cursors with default ones when they do a software update, so keep backups. Sep 6, 2012 at 4:34
  • 2
    In xcode 5.0.2 the location hasn't changed, but the names have. The PNGs are no longer present, only one single TIFF by the name of DVTIbeamCursor.tiff - this should be the only thing you need to replace for standard or retina screens. Dec 8, 2013 at 15:09
  • 2
    I created a public repo for a version of this that should work on light and dark colored backgrounds, because it is black with a white outline.
    – Eric G
    Jan 23, 2014 at 1:10
8

I created a public repo for an ibeam cursor that should work on light and dark colored backgrounds, because it is black with a white outline. It includes succinct instructions, and a TIFF file ready to drop in to the Xcode bundle.

Update: the git repo includes a shell script that makes installation quite easy.

2
  • 1
    You sir are a saint. I'm going to mention here that there is a install.sh script that you can run out of the box making this EASY PEASY.
    – noobular
    Jul 14, 2015 at 18:52
  • 1
    Script made it very easy. Nice work. Even patched the beta.
    – user470763
    Aug 12, 2015 at 16:27
2

Unfortunately this is a difference between Carbon and Cocoa cursors—Cocoa cursors won't invert; at least, up to Snow Leopard. In Lion, even Carbon cursors behave like you don't want.

If you've got a machine running Snow Leopard or earlier, compare the I-beam behavior in BBEdit or TextWrangler (which use Carbon cursors), for example; it'll become entirely white on a black background. Even this is a bit fragile—when I change the screen magnification, BBEdit's formerly-white cursor becomes black.

You can still set a Carbon cursor in your Cocoa app. Try this in a NSTextView subclass:

#import <Carbon/Carbon.h>
[...]

- (void)resetCursorRects;
{
    // disable existing cursor setting behavior
}

- (void)cursorUpdate:(NSEvent *)event;
{
    SetThemeCursor(kThemeIBeamCursor);
}

- (void)updateTrackingAreas;
{
    for (NSTrackingArea *trackingArea in [self trackingAreas])
        [self removeTrackingArea:trackingArea];

    NSTrackingArea *trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect options:NSTrackingCursorUpdate | NSTrackingActiveInKeyWindow | NSTrackingInVisibleRect owner:self userInfo:nil];
    [self addTrackingArea:trackingArea];
}

(In 64-bit you'll see that this function is excluded from the headers, but the symbol is there and works.) If you're sufficiently motivated, you could potentially patch Xcode to do some variant of the above, perhaps from an Xcode plugin.

If you're on Lion, here's what it is supposed to look like:

Inverting cursor

So I'd suggest filing a bug with Apple to make the systemwide I-beam cursor (or NSCursor in general) properly handle dark backgrounds; it's not an Xcode-specific issue and it should really have been fixed years ago.

3
  • 1
    Thank you for the very in-depth answer. I did end up filing a bug with Apple shortly after asking the question here.
    – phloopy
    Aug 31, 2011 at 22:55
  • SetThemeCursor is undefined in the OSX 10.7 headers, at least according to my compiler.
    – Eric
    Nov 6, 2013 at 21:28
  • Nope, still there in HIToolbox/Appearance.h in the 10.9 SDK even - but as I mentioned in my answer, 32-bit only. Also as I mentioned, in Lion and later, there's no point in using it as it doesn't provide the improved functionality. If you care, file a bug and maybe it'll eventually get fixed in Cocoa. Nov 6, 2013 at 21:47
2

For Xcode 5 preview, i have created a better I-Beam for Dark color templates. You can use it freely. http://www.scigems.org/wordpress/?p=92

1

According to this thread on the Apple forums:

https://discussions.apple.com/thread/2811447?start=0&tstart=0

the "cursor color" referred to in the XCode 4 fonts and colors preferences is actually the cursor you see when you have clicked in a window to enter text.

The I-beam cursor you see when you are moving the mouse around in the code editing window is a Mac-OS wide feature which you cannot change in XCode.

The forum post above suggests looking for third party software to change attributes of the system-wide I-beam cursor.

Another post points out that you can at least edit the cursor size to make it more visible:

System Preferences -> Universal Access -> Mouse & Trackpad -> Cursor Size

1
  • I went with a slightly enlarged cursor size. It doesn't bother me as much anymore, but when another developer uses my computer the size annoys them quite a bit :p Thanks for the tip
    – phloopy
    Aug 31, 2011 at 22:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.