Categories
Apple

error: btn: invalid btn_btree.bt_key_count

I recognised the symptoms:

  1. Excessive disk trashing.
  2. General slow down.
  3. Backblaze and Time Machine causing the rainbow spinner.

My filesystem needed first aid. I think I can trace this back to the latest macOS update. I swear that half the updates cause filesystem corruption of some sort, but it also feels like I’m running First Aid at least once a month anyway!

Unfortunately for me, the error this time was:

error: btn: invalid btn_btree.bt_key_count

Apparently Diskutil can’t fix that error. The only thing you can do is erase the drive, reinstall MacOS and then restore your data. I was dreading it.

I have a Time Machine backup but I decided to make another backup of my home directory, while logged into another account. Lucky I did as an IO error showed up in Library/Caches/ – thankfully I think in an Apple app I don’t use.

I expected the business of restoring everything to be awful, but in the end the MacOS installer fired up Migration Assistant which let me restore my last Time Machine backup.

With that done it was time to install Brew again. The first package to go back in was coreutils but “brew reinstall” has a bug where it won’t accept parameters. I should have used “install” but “reinstall” withย  “–with-default-names” doesn’t work. Also coreutils and related packages are “keg-only” now so no symlinks to /usr/local/bin are made. You have to run “brew link” to link all the commands. It was a simple job then to rename each file, removing the “g” prefix.

I’ll find more things as I go that aren’t configured I’m sure, but thankfully restoring from Time Machine made the job much easier!

Categories
Apple

High Sierra and coreutils

Since MacOS High Sierra has been out for a long time this is probably old news to the tiny minority using coreutils. When you upgrade you might find that “df” and other commands don’t work properly.

Every time I opened a terminal after upgrading I saw errors saying commands had been aborted. When I ran “df” it would abort immediately.

I thought the upgrade had damaged my filesystem, especially since it introduced APFS. I ran “First Aid” in Disk Utility several times, both live and in recovery.

It then occurred to me to try the MacOS df in /bin/. It worked!

Coreutils is the package that includes lots of command line tools like “df”. I installed it using brew so the following fixed the problem:

brew reinstall coreutils

I noticed it put everything in /usr/local where my original commands were in /opt/ so changing the PATH in my .zshrc was necessary too. Everything was back to normal again! ๐Ÿ™‚

EDIT: Some other commands were messed up. “find” had changed, but then I realised it probably isn’t in coreutils and I was using the MacOS version. This page led me to the right package names and the following command line:

brew reinstall coreutils findutils gnu-tar gnu-sed gawk gnutls gnu-indent gnu-getopt --with-default-names

The “–with-default-names” parameter restores the original filenames, removing the “g” prefix. Everything outside of the coreutils went in /usr/local/bin/ which I made sure was added to the path too.

Categories
Tech

Unmount USB drives from a script in macOS

I have a number of external drives hanging off my laptop, but sometimes I want to disconnect them. I used to go into Finder and click the eject button but I have five drives now so that’s getting unwieldy.

There are a few different ways of doing this. I wrote a small BASH script based on information here.

I created a shell script on my Desktop, added the following, changing DRIVE to the volume path for each of my external drives:

osascript -e ‘do shell script “diskutil unmountDisk /Volumes/DRIVE”‘

After creating that script I made it executable with chmod +x and as I use iTerm2 as a terminal I associated .sh files with that (Finder, right click on script, Get Info->Open With).
Every time I double click the script a new tab opens in iTerm2 and I see the progress of the unmount commands!

Categories
Tech

Remapping the Keyboard on a new Macbook Pro

I must have an odd keyboard, at least for one that’s paired with a Mac. It’s a Microsoft split keyboard and has a bunch of extra keys that aren’t on a Macbook Pro keyboard, like a dedicated # key and the keys are all over the place compared to the laptop keyboard. But I like it that way.

I’ve heard comments from people who use my laptop and they are confused by how shift-2 doesn’t print @ but ” instead, and the key by the left shift prints \ instead of ~ (which is over by the Return key). They’ll say, “Oh, it’s some sort of PC keyboard?” Well, yeah.

This is not the first time I’ve had to fix my keyboard. A long time ago Justin Mason created a useful Irish Fixed Keyboard Layout, but for some reason with this latest hardware upgrade it wasn’t working exactly as planned. The #, \ and ` keys were mixed up. Luckily, with the help of the Key Codes app I could detect the the key code of the physical key pressed. For example, the key next to the left shift is key code 10 so it was just a matter of editing the keyboard layout in a text editor and changing that to output “\”. Logout and login to refresh and the key works!

What’s odd, is that this keyboard layout has served me well for almost a decade and didn’t need editing, which is why I’m documenting it in this post.

I looked at both Ukelele and Karabiner but the former looked overwhelming (yeah, then I went editing XML by hand..) and the latter doesn’t work in macOS Sierra (there’s a simplified “elements” version for Sierra). Then I thought I should just edit the keyboard mapping directly. ๐Ÿ™‚

Categories
Linux

Find Duplicate Files in MacOS

In the past I’ve used FSLint or even some BASH magic to find duplicate files but I have a huge archive of photos and videos, some of which were renamed during import, and some were accidentally imported more than once, or moved about. It’s somewhat chaotic

dupeguru

So I was very glad to find dupeGuru! It’s a powerful application for MacsOS and Linux that allows you to scan one directory or more for duplicate files. It can search by content, or match filenames. It has modes for music and pictures, but I’ve stuck with the standard search as I want to only look for files that are 100% the same.

It found several gigabytes of duplicates for me, and it has a useful feature that symlinks duplicates to their parent. Even though the dupes still exist, they’re not taking up any space.

The developer is looking for help to maintain the project. You can find more information and source code too on the dupeGuru GH page.

Categories
C64

VirtualC64 for Mac OS X

VirtualC64 is a new Commodore 64 emulator for Mac OS X. It’s a promising project, let down by the fact that it’s still in beta but by the looks of things development is moving at a steady pace.

When you first run the emulator it will ask you for C64 roms: basic, kernal, chargen and vc1541. Ironically, you can find all these roms inside Vice, another C64 emulator. Look in /Applications/VICE.app/Contents/Resources/ROM/. The 1541 ROM is DRIVES/dos1541.

Loading a game or demo is as easy as dragging the d64 or t64 image into VirtualC64. When you do you’ll see a dialog like this.

picture-6

“Flash file into memory” works great for single load programmes but multiload could be a problem. I tried Armalyte. Mounting the d64 as a disk didn’t work. I couldn’t type anything. Loading the first file on the disk by flashing it brought up the crack intro but failed to load. The neat integrated debugger (click “Inspect”) showed the emulator had died doing jsr $2020 and unfortunately at 2020 was another jsr … ($20 is the character code for a space if memory serves, and the machine code for jsr was $20, so memory was full of spaces!)

picture-3

Blue Max worked much better, as did a 3D Pool game I tried. the crack by Remember included the documentation and again using the debugger I watched as the programme checked for the various key presses. Geeky I know but it brought a smile of recognition to my lips. Here’s that debugger in all it’s glory. Anyone familiar with the C64 should recognise the code beginning at 1AA0. (I had to look up what D016 does. It’s the screen mode. I had completely forgotten. It’s only been 16 years.)

picture-10

One thing it has going for it over Vice, is a real fullscreen mode. The current version of Vice uses some dodgy resolution changing in Linux (that I rarely got to work properly without screwing up my desktop) and I couldn’t get to work in Mac OS X at all. Fire this baby up in fullscreen mode and you’ve got your very own C64 laptop! Cool or what eh?

As luck would have it VirtualC64 has blown a fuse just as I finish this post. If you have a usb joystick plugged in and activated in port 2 it does strange things. First the keyboard wouldn’t work, and flashing a file didn’t run it automatically. Then the keyboard sort of worked but the left arrow character appeared for most key presses. Odd stuff. Unplugging the joystick and restarting the emulator fixed that problem.
Even my Bits ‘n’ Bobs demo worked in it! (Bah, all my screenshots failed. They only show white. I wonder if the emulator does strange things to the Mac while emulating mixed video modes? I mixed character and video modes in the screens I tried to capture, ah well.)

VirtualC64 is a very promising C64 emulator, and it’s GPL too! I’ll certainly be keeping an interested eye on it, and I wish Dirk and the other project members the best of luck with it.