I\'ve had a bit of this trouble, where it freezes just after programming, but it goes away when I unplug it. The problem is this: If your program isn\'t using DigiKeyboard, DigiUSB, or another of the digispark usb libraries (or some other v-usb firmware) when the device boots the user program it starts using the USB data lines for things which aren\'t usb data. Sometimes this confuses the hub on the mac laptops. Usually mac laptops have at least one USB port which connects directly to a root hub, and some others which connect to a secondary hub as well as connecting in the keyboard, trackpad, bluetooth, and webcam. The digispark is confusing this secondary hub, I think. Try using a different usb port and the problem might go away. Also, try not to do anything to pins 3 or 4 unless you really need to - these are the USB pins. Leaving them both as pinMode OUTPUT, digitalWrite LOW, should keep the computer thinking nothing is plugged in to that USB port, and keep it from getting muddled up.
I\'m using a 2011 Macbook Air which has this same trouble, except for the repeating until reboot part. That\'s pretty annoying!
Open up the Console.app in /Applications/Utilities to see a live system log - you\'ll probably see some USB errors around the time when the keyboard stops working. They might be informative?