Changed User ID Whilst Logged In (Still Logged in Now)
Reboot your Mac to Single User Mode (cmdS while booting) and enter at the prompt:

/sbin/fsck -fy
/sbin/mount -uw /


Launch opendirectoryd:

launchctl load /System/Library/LaunchDaemons/com.apple.opendirectoryd.plist


You will get some error messages - repeatedly.

Then enter (replacing username with your real user name):

dscl . -read /Users/username UniqueID


You should get something like 272 (if you changed it to 272 accidentally)

Now change it back to 501 again and check the result:

dscl . -change /Users/username UniqueID 272 501
dscl . -read /Users/username UniqueID


which should yield the original 501.

Then enter exit and boot to your GUI or better: reboot your Mac immediately with shutdown -r now to avoid errors based on the premature launch of opendirectoryd. I got some kextunload errors trying to shut down/reboot after booting directly to the GUI.