Categories
Mac

Move between Code tabs on Mac

I primarily use macOS but I also use Windows on a regular basis. Or maybe I should say I have to use Windows because of various workplace activities where it makes it easier to do what I have to do. But that is invariably because of corporate IT policies defined by people who, due to malice or just lack of knowledge, go out of their way to make life difficult for non-Windows people.

If I were to point out one thing that irks me it is the inconsistent use of various keyboard shortcuts on Windows. The use of the control key for a lot of things also leads to very awkward finger positions. As a comparison, the command key on Mac is right under the left thumb so it is super easy to achieve various key combinations without moving the hands.

Coming from macOS to Windows I couldn’t wrap my head around how people could actually stand the use of the control key for so many shortcuts and briefly tried to remap the keys to switch ctrl and alt around. But that led to other problems so I abandoned it and, reluctantly, succumbed to the Windows way of doing things – on Windows.

But on macOS I really expect things to work in a consistent manner with all other applications so I was mightily surprised to notice that the default way to switch tabs on Visual Studio Code on macOS uses the control key. Every other program that I know of on macOS that allows the user to jump between tabs uses the command button plus number keys. Even Microsoft’s own Edge browser does it. But not Visual Studio Code! Switching between open documents is something I use frequently so this was a real nuisance. I was frustrated and almost gave up on VS Code.

Luckily VS Code allows for simple keybindings but it is not super intuitive. This is what I did:

  1. In VS Code, open Keyboard Shortcuts (under Code > Settings…)
  2. Open Keyboard Shortcuts (JSON) in the top right, the small document icon with an arrow
  3. Add the mappings below, or use the attached file

This enables Cmd plus numbers to switch between open tabs. Like the standard Cmd+9 switches to the last tab. It is also possible to use Option+Cmd plus arrow keys to move right and left among the tabs.

My sanity is restored. I just don’t understand why this couldn’t be the default mapping for VS Code on macOS to begin with.

[
  {
    "key": "cmd+alt+[ArrowLeft]",
    "command": "workbench.action.previousEditor"
  },
  {
    "key": "cmd+alt+[ArrowRight]",
    "command": "workbench.action.nextEditor"
  },
  {
    "key": "cmd+1",
    "command": "workbench.action.openEditorAtIndex1"
  },
  {
    "key": "cmd+2",
    "command": "workbench.action.openEditorAtIndex2"
  },
  {
    "key": "cmd+3",
    "command": "workbench.action.openEditorAtIndex3"
  },
  {
    "key": "cmd+4",
    "command": "workbench.action.openEditorAtIndex4"
  },
  {
    "key": "cmd+5",
    "command": "workbench.action.openEditorAtIndex5"
  },
  {
    "key": "cmd+6",
    "command": "workbench.action.openEditorAtIndex6"
  },
  {
    "key": "cmd+7",
    "command": "workbench.action.openEditorAtIndex7"
  },
  {
    "key": "cmd+8",
    "command": "workbench.action.openEditorAtIndex8"
  },
  {
    "key": "cmd+9",
    "command": "workbench.action.openEditorAtIndex9"
  },
  {
    "key": "cmd+0",
    "command": "workbench.action.lastEditorInGroup"
  }
]
Categories
Gadgets Mac

The time is 9:41

You may have noticed that the iPhone time on Apple presentations is always 9:41. How come? This goes back to when Steve Jobs launched the iPhone in 2007. At the time the time displayed was 9:42 and it was subsequently used for all promotional screenshots until the iPad was launched when the time was changed to 9:41.

Having a static time for all screenshots is good as it makes it easier to produce screenshots for presentations at different times and be able to combine them without the time jumping around. In addition it is also a nice historic reminder of the launch of the iPhone.

This is all very well, but how do you go about producing screenshots that mimic this behaviour. One option is to connect the iPhone to a Mac via USB and then run QuickTimePlayer on the Mac and start a recording. This will force the time displayed on the iPhone to 9:41, blank out any operator name and change the signal strength to maximum.

This works fine but requires a physical device. This can be tricky when submitting apps to the App Store and you have to provide screenshots for all various screen sizes. Another alternative is to download SimulatorStatusMagic, a free Xcode project on GitHub, compile it and install it in the various Xcode iPhone simulators.

Running the app in the simulator shows a GUI that allows the user to set the time, or use the default 9:41 time. Then switch to any other app in the simulator and take whatever screenshots are required.

Categories
Mac

Missing recipients when emailing group in OS X

Sometimes when emailing a group from the contacts application in OS X El Capitan one or more of the addresses will be missing from the recipient list in the mail application. The missing recipients can be added manually to the recipient list but they will be silently dropped when the mail application expands the group into its members.

It is very unclear why this happens but a workaround seems to be to delete the mail addresses from the failing recipient and add them again. After that, the group expands to the full list of members.

Categories
Blog Computers Mac

Still broken unison brew

I wrote in an earlier post about how the brew build of unison is broken due to it defaulting to ocaml 4.02. Back then it was possible to checkout an old version of ocaml but since then changes to brew seem to have closed that option. Instead of being able to use brew to install a particular version of unison I had to install it from source and include the correct version of ocaml. This is how I did it.

First uninstall any existing brew installations of unison and ocaml

brew unlink unison
brew unlink ocaml

Then download ocaml 4.01 and compile from source.

wget http://caml.inria.fr/pub/distrib/ocaml-4.01/ocaml-4.01.0.tar.gz
tar -xvzf ocaml-4.01.0.tar.gz
cd ocaml-4.01.0
./configure
make world.opt
sudo su
umask 022
make install
exit

Finally, download unison 2.40.102 and compile from source

wget http://www.seas.upenn.edu/~bcpierce/unison/download/releases/unison-2.40.102/unison-2.40.102.tar.gz
tar -xvzf unison-2.40.102.tar.gz
cd unison-2.40.102
make UISTYLE=text

The unison binary is in the current directory. Just copy it to a location within your path and you should be set to go.

Featured photo by Kuba Bożanowski (https://www.flickr.com/photos/jbozanowski/4132669334/).

Categories
Blog Computers Mac

Broken unison brew on Yosemite

I rely on Homebrew for many of the command line tools I use on my computers. One such tool is unison, a powerful synchronisation application for keeping files in synch. I use it as a way to allow me to work on any one of my computers with maintained security and without having to send my files to a cloud provider. These days there are several alternatives with Bittorrent Sync as probably the best option.

One caveat with unison is that it requires all peers to use the same version of the binary. But with a limited number of peers this is not a major issue.

For a long time I just used precompiled binaries for OS X and Ubuntu using the same unison version. Then, as I reinstalled the Ubuntu server and got a newer version I realised that this was the same version (2.40.102) that was installed with brew so I ditched the previous binaries and installed unison using brew instead. That worked for two OS X computers but on the third one I got an error when synchronising the files:

Uncaught exception Failure("input_value: bad bigarray kind")

This exception occurred on a completely reinstalled Macbook. The exception seems to be caused by unison using an incompatible version of ocaml compared with the ones on my other computers (the brew version is compiled against ocaml v4.02 while my other clients were using 4.01).

As I see it there are two potential solutions to this problem:

  1. Upgrade all peers to the new ocaml version
  2. Build a version of Unison using the older (<4.02) version of ocaml

For this article I chose the latter alternative.

First, I needed to install version 4.01 of ocaml. Brew will by default use the most recent stable version (right now 4.02) but can be made to install older versions if required. To list the existing versions run:

$ brew versions ocaml

4.02.1   git checkout a772c80 /usr/local/Library/Formula/objective-caml.rb
4.01.0   git checkout 924387b /usr/local/Library/Formula/objective-caml.rb
4.00.1   git checkout b04e346 /usr/local/Library/Formula/objective-caml.rb
4.00.0   git checkout e2140fd /usr/local/Library/Formula/objective-caml.rb
3.12.1   git checkout df16522 /usr/local/Library/Formula/objective-caml.rb
3.12.0   git checkout 0476235 /usr/local/Library/Formula/objective-caml.rb
3.11.2   git checkout ed51a5b /usr/local/Library/Formula/objective-caml.rb

If the versions command above shows ‘Error: Unknown command’ then just run

$ brew tap homebrew/boneyard

After that, run the versions command again and it should work. This will display a warning that brew-versions is unsupported. Ignore this for now and notice the line with version 4.01.0.

$ cd `brew --prefix`/Library
$ git checkout 924387b /usr/local/Library/Formula/objective-caml.rb
$ brew install ocaml

Now we should have ocaml v4.01.0. Then, compile unison from source in a temporary directory that you can remove afterwards:

$ cd /tmp
$ wget http://www.seas.upenn.edu/~bcpierce/unison//download/releases/unison-2.40.102/unison-2.40.102.tar.gz
$ tar -xvzf unison-2.40.102.tar.gz
$ cd unison-2.40.102
$ make UISTYLE=text
$ sudo cp unison /usr/local/bin/

Now you should have a working unison installation using ocaml 4.01.0

Featured photo by Giuseppe Milo (https://www.flickr.com/photos/giuseppemilo/15602907800).

Categories
Blog Computers Mac

Yosemite desktop clock

yosemite-desktop-clock

The desktop is a very underused resource on many computers. It often just sits there as a backdrop to files and folders. But using the tool Geektool on OS X the desktop can be put to very good use.

Personally have have a big clock in the lower left corner of my desktop. I have done this by just dragging two shell script boxes from the Geektool application. In these two I run the following two shell commands respectively:

date '+%A, %b. %d'
date '+%H:%M'

yosemite-desktop-clock-boxes

I use the font Lucida Grande regular and set the font colour to white. For the date I use the size 24pt and for the clock 96pt. I then set the clock to update every ten seconds and the date to update every five minutes. With this I could potentially disable the clock in the menu bar but I have chosen to keep it there for those times that the desktop clock is obscured by windows.

In addition to this I also use this method to display an always up-to-date text based todo list right on the desktop of my various computers.

Categories
Mac Windows

Access Windows servers from OS X

After a hiatus of a couple of years I have recently come back to working with Windows servers – besides OS X and various Linux distributions, which have been my usual working tools lately. I realised that my old tools to access Windows servers would no longer do the trick. The Microsoft Remote Desktop Connection Client for Mac was never really very good but I had become used to Cord and it, too, would no longer work.

RDP problem

Apparently the problem is due to a difference in protocols between the client and the server and the two couldn’t negotiate properly on what protocol to use. I first tried to modify the server to default to the old RDP protocol and not try TLS. I even kept a virtual Windows client at hand to run whenever I felt a need to connect to a remote Windows server.

It turns out the absolutely best solution in these cases is to use the Microsoft Remote Desktop app, available on the Mac App Store for free. It is truly a great application for this purpose and allows the user to keep a list of servers and connect to them quickly and easily. For the ultimate in user experience, run the Windows terminal full screen and use the three finger swipe to quickly switch between the remote server and the local OS X system. Sweet!

Categories
Blog Mac

Git and Textmate

Since I started using git (and when using svn before that) I have always typed commit messages on the command line using the -m switch. While that works the usability is not exactly fantastic. The funny thing is that it is very easy to change. I do all my development on OS X and my text editor of choice is Textmate. With that combination it is just a matter of issuing the following command:

git config --global core.editor "mate -w"

This will also make it easier to abide by best practices about how to write commit messages.

Categories
Computers Linux Mac

Create bootable Ubuntu USB stick

I don’t create bootable USB sticks that often but every time I do it I think that it’s harder than it really is and start to search the web for walkthroughs.

This post could also simply be written: Look at the Ubuntu download page.

Here is the process for OS X:

  1. Download ISO file of the operating system you want to put on the USB stick
  2. Open the terminal
  3. Convert the ISO file using the convert option of hdiutil: hdiutil convert -format UDRW -o /path/to/target.img /path/to/source.iso
  4. Run diskutil list to get the current list of devices
  5. Insert the USB stick
  6. Run diskutil list again to determine the device node assigned to your USB stick
  7. Unmount the USB stick: diskutil unmountDisk /dev/diskN
  8. Write the image to the USB stick: sudo dd if=/path/to/disk.img of=/dev/rdiskN bs=1m
  9. Eject the USB stick: diskutil eject /dev/diskN
Categories
Mac

Install rmagick gem in OS X 10.8

When installing the rmagick gem under OS X 10.8.1 (Mountain Lion) I got the following error on a system using RVM, Ruby 1.9.2 with ImageMagick installed through Brew.

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
...
checking for stdint.h... *** extconf.rb failed ***
...

The error appears to be due to some issues with the OpenMP implementation in OSX. The solution that worked was to uninstall ImageMagick, then reinstall it without OpenMP support:

brew uninstall imagemagick
brew install imagemagick --disable-openmp

Since I didn’t have X11 on this computer I got warnings about missing X11 and had to dismiss a number of dialogs during compilation. But it went through and seems to be working. At least I could then do a bundle install on my Rails application.

css.php