2021-02-25

Mac Finder still shows incorrect folder sizes

It's been two years, and the Mac Finder still shows incorrect folder sizes --- on macOS 10.15 Catalina.

A single screenshot shows how hilarious / sad this is:

 

The screenshot here shows the Finder thinking my "lol" folder is 17.92 GB.

But inside "lol" are two sub-directories: "magic", and "movs".  Finder thinks those two folders are zero KB.

Inside "movs" are a bunch of MP4 files that together are several hundred MBs.

Bring up the terminal to check, and du shows "lol" is actually 211 GB !!!

For the record, du is correct.  "magic" contains a lot more files.

Oh Apple... I can't recall classic Mac OS Finder, since the System 7 days, ever having this level of... mistake? incompetency? error?  If every time the Finder's Get Info window is open, it would just spin out a du sub-process to get the folder size, then it wouldn't get it this wrong.  But nope.

And for the record, I had to restart the Mac to get the folder size to show correctly.  Something with the Finder got really screwed up I guess.

This problem has been known for two years, since macOS 10.14.  See:

- 2019 February: Finder Shows Incorrect Folder Sizes --- on macOS 10.14

- 2020 February: What You See in the Finder Should Always Be Correct

- 2021 February: here we are...

2021-02-19

Remap Capslock to Control in VirtualBox Linux guest on Windows host

Let's say you have Debian Linux guest OS in VirtualBox, running on a Windows 10 host.

Here's how to map capslock to control

If it was a Mac host, it'd be super easy: install and use Karabiner-Elements to remap capslock to control in the Mac host [3]. Now both host and guest Linux will have the remapping.  Done.

On Windows, it's not so easy.

You basically have to do the remapping in both Windows and Linux.  Follow the ideas here:

  1. Remap one key to another in Windows, like Capslock to Control 
  2. Remap one key to another in Linux, like Capslock to Control

Set shift key to break capslock for greater reliability

For greater reliability, you should also set shift key to break capslock.  So adding that to the Linux command for making capslock a control key, you'd get this command to run instead:

setxkbmap -option -option caps:ctrl_modifier -option shift:breaks_caps

The first blank "-option" clears any previously set.  Then the second option sets the capslock to control.  The third option makes shift key break capslock.

This is needed because sometimes switching between Windows host and Linux guest, the capslock gets locked down.  Now a quick tap on the shift key should break that lock.

What's wrong with remapping in Windows host only?

If you remap capslock to control in Windows host only, it'll actually sort of work in the Linux guest --- except in Linux, the capslock will now function as both capslock and control!

I did that for a while and didn't notice as I tested it inside Linux guest.  Capslock-T in Firefox still created new tabs!  Works!  But if you start typing, you'll notice things are in all caps until you tap capslock again, and vice versa.

What's wrong with remapping in Linux guest only?

If you remap capslock to control in Linux guest only, it'll actually work!  Except the capslock LED light will turn on/off with each click.  And if you switch back to Windows, capslock might have been engaged as you used capslock-as-control in Linux guest.

That's why you must do the remapping in both Windows host and Linux guest.  That way they stay in sync with each other, and the LED light won't turn on.

Capslock LED light in Linux

As I was troubleshooting the Linux guest only remapping, and noticed the capslock LED light would turn on/off, at first I thought the problem was in Linux.

And in case it is for your situation, here's how to fix or check.

xmodmap -e 'clear Lock' is suppose to clear the capslock LED from being turned on [1].  Try that, despite xmodmap being a deprecated system.

You can check if the LED is being turned on by Linux by running this command:

cat '/sys/class/leds/input5::capslock/brightness'

Turns out the LED property is represented as "just a file" on Linux you can open and read [2].

In my case, that command showed the LED was always off from Linux guest's point of view.  Turned out Windows host was controlling it.


Reference

[1] How to prevent the caps-lock toggle effect, without remapping or disabling it?

[2] Turn the Caps Lock LED on, while keep Caps Lock status is off

[3] Actually, I think Mac's System Preferences even have a built in setting for doing this remapping, so Karabiner might not even be needed for this single simple remapping.

2021-02-10

Remap one key to another in Linux, like Capslock to Control

Linux is known for choice and customizability.

So it's ironic but when it comes to keyboard and mouse key remapping and scripting, Linux is the more challenging than Windows (using AutoHotKey) or Macs (using Karabiner-Elements).

I'll link to some guides and answers below, but some big picture ideas to be aware of in 2020 for Linux key remapping:

xmodmap is deprecated

Prefer using setxkbmap if it'll do what you want.

Some xmodmap functionality remains, but it's clearly a deprecated system and it sometimes doesn't work.

I tried to do some simple key remapping with it on Debian LXDE and it didn't work for me.

setxkbmap is preferred but complicated

It has many common remappings like turning capslock to control [1]:

setxkbmap -option -option caps:ctrl_modifier

The first blank "-option" clears any previously set.  Then the second option sets the capslock to control.

Swapping the left control and alt keys can be easy to do as there's a direct option for it too.

Running setxkbmap only affects the current session, so logging out will wipe the settings. To make it auto set on login, put it in a script run from .bashrc or similar.

Limitations

But what if you want to swap the right control and alt keys instead?  Or some weird 4 way switch of keys?

There many be some set of xkeyboard-config options that'll work, but it's not straightforward the way it is on a Mac with Karabiner-Elements.

You also may have to find and use keycodes or events generated by your keyboard or mouse interactively.  Do this using the xev command line app [3].

 If you want to go down this route, be sure to check out:  A simple, humble but comprehensive guide to XKB for linux.  But if you want an easier way, check out the last section below because, of course, there's an app for that!

Show setxkbmap options

To find what options are supported by setxkbmap, you can run [2]:

man xkeyboard-config

man xkeyboard-config is not complete: e.g. right alt to right control

More annoyingly, turns out running man xkeyboard-config does not list a complete list of what setxkbmap can do!

For example, let's say you want to make the right alt another right control key.

It's not listed in man xkeyboard-config but it is easily possible!  Just run:

setxkbmap -option ctrl:ralt_rctrl

It is listed in a lower level description file at however [4] :

/usr/share/X11/xkb/rules/evdev

And if you're up to it, you can change the low level description files that setxkbmap uses to give you great control over the keyboard remappings.  But it's not easy the way it is on Macs and Windows!

Remapping single keys using hwdb files

This is lower level than setxkbmap, but it's not deprecated like xmodmap, and for single key to single key remapping, it seems to work well.

Detailed instructions found at: Remapping keys using hwdb files

Use an app to intercept and inject keys

This method allows more complex hotkeys and combos to be remapped to almost arbitrary input.

This is really new.  Try out  sezanzeb's key-mapper.  It works with X11 and Wayland, and has an easy GUI interface to it.

Here's a nice guide for it: Remap Keyboard And Mouse Buttons On Linux With The New Key Mapper GUI (Supports X11 And Wayland).

Since key-mapper is a Python program, you'll need Python to run it anyway.  So on Debian, you might as well just install Python and pip, then use pip to install it.

Key-mapper is not available in Debian's package system, so you'll have to download and install it from the key-mapper Github repository.

In fact, Debian has a package called "keymapper" that is not the key-mapper you're looking for.  Using apt to install key-mapper, even key-mapper's own pre-packaged .deb file, kept suggesting the wrong "keymapper" package instead.

Probably easiest to just install it with pip!

(NEW!)  Check out kinto if you're interested in mac-style hotkeys on Linux and Windows!


References

[1] How to swap Ctrl and Caps Lock keys in Linux

[2] List all valid kbd layou ts, variants and toggle options (to use with setxkbmap)

[3] How to prevent the caps-lock toggle effect, without remapping or disabling it?

[4] Map right alt to left control

2021-02-02

Enable 3 Finger Drag on Windows

3 Finger Drag (3FD) is not available on Windows, and not built-in on Linux

For Linux support, I'll write another post in the future.

On Windows, we can achieve something similar.  Let's call this:  3 Finger Tap to Drag Lock.

It's Dakshin's idea [1], refined further [2] and tweaked below.

What's 3FD anyway?

3 Finger Drag refers to a Mac accessibility feature.  When enabled, if you place three fingers on the Mac's trackpad or touchpad, then move those fingers in unison on the trackpad, the mouse pointer behave as if you left-clicked-and-are-dragging.

It's a better more ergonomic alternative to the tap-twice-and-drag method that's common on Macs, Windows, and Linux.

It's better because there's less finger tapping movement which can develop into "trigger finger" type repetitive strain injury.  If you drag things around a lot, tap-twice-and-drag plus another tap to deactivate dragging starts to add up to being a nuisance!

And at least for me, when dragging using the  tap-twice-and-drag gesture, I often have trouble continuing to drag mid-drag if I lift my hand away from the trackpad to reposition.  And ironically, I also have trouble disengaging the drag once I've reached the target of the drag motion too!

3 Finger Tap to Drag Lock (3FTD) on Windows

The gesture allows you to tap on the trackpad with 3 fingers, which will "lock" the left click down.  Then you can use 1 finger to move the cursor around, thus dragging what's clicked on!  A single tap again will disengage it.

You'll need to install AutoHotKey (AHK) as this is a script continuously running in the background to make it happen.

Installing the AHK Script

Make a text file and copy the script below into it, then save the text file with a .ahk file extension.  Double click the .ahk script file and AutoHotKey will run it to give you this 3FTD behaviour.

If you want the script to run every time you log in to Windows, you'll need to move the script or add a shortcut to it into the Windows startup folder.  See detailed instructions [3] for that.

ThreeFingerTapDragLock.ahk

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#SingleInstance force

drag_enabled := false

; Key combo for 4 finger tap:  #^+F24
#^+F22:: ; 3 finger tap
    if (drag_enabled) 
        Click, Up
    else
        Click, Down
    drag_enabled := !drag_enabled
return

#If drag_enabled
LButton::
    Click, Up
    drag_enabled := false
return
#If

Limitations of this script: games and VirtualBox

Chances are, this script won't work inside games.  Many games access the mouse and keyboard at a lower level than what AHK can effectively manipulate, or has anti-scripting functionality built-in.

AHK also doesn't play nice with VirtualBox since it's virtualizing the keyboard and mouse for the guest OS!

To avoid problems with VirtualBox, I tweaked the above script so it only works outside of it:

ThreeFingerTapDragLock_OutsideVBox.ahk

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#SingleInstance force

drag_enabled := false

#If !WinActive("ahk_exe VirtualBoxVM.exe")
; Key combo for 4 finger tap:  #^+F24
#^+F22:: ; 3 finger tap
    if (drag_enabled) 
        Click, Up
    else
        Click, Down
    drag_enabled := !drag_enabled
return


#If drag_enabled && !WinActive("ahk_exe VirtualBoxVM.exe")
LButton::
    Click, Up
    drag_enabled := false
return
#If

Note about the Key combo

My trackpad's 3 finger tap sends the key combo Win+Ctrl+Shift+F22.

And it's F24 instead of F22 if I 4 finger tap.

So the Key combo in the scripts above can be easily changed if you prefer a 4 finger instead of 3 finger gestures.

But also, if your laptop or vendor trackpad is different, you'll have to use AHK to find out the appropriate key combo to put in the script instead.


References

[1] Enable 3 Finger Gesture for click and drag on Windows and Linux

[2] AutoHotKey - Three finger dragging script causing minor issue, how to fix?

[3] How to Schedule AutoHotKey to Start Up with Windows