Skip to content
  • Florian 
  • 5 min read

The kaleidoscope: URL scheme

Kaleidoscope 5.1 comes with a URL scheme, yet another new way to integrate with other apps on your Mac. Why would someone need that? Glad you asked!

Some apps are unable to use any of the other methods we already provide, like our system services, the share extension, Shortcuts, a command-line command, custom integrations, … But more importantly, it may just be most convenient to provide everything needed to compare multiple files in one single “command” in the form of a URL. Many apps on macOS detect URLs and make them interactive links. A single click is enough to open a URL, and that click will then open a comparison in Kaleidoscope.

There’s a very specific use case we had in mind when adding this feature: running tests within Xcode, in particular snapshot testing using swift-snapshot-testing. Let’s start with the benefit: here’s a default error message you would get for a failed test comparing a previous snapshot of a screen with the current test run:

A simplistic example based on the Xcode SwiftUI multi-platform template. In the testExample function, we are wrapping the ContentView of the app with a UIHostingController, so we can create a snapshot of it

Note the folks of swift-snapshot-testing even suggest to use ksdiff as a diffTool instead. Then this is what you get in Xcode:

Now we can select that ksdiff command inside the error bubble:

And paste the command into a Terminal window to open the comparison in Kaleidoscope:

Pasting the text from the error in Xcode into Terminal will open the comparison of both images in Kaleidoscope.

This is already a huge improvement, compared to seeing only two file:// urls in the Xcode error, which we then could open manually in Kaleidoscope. But now we can do even better…

New in Kaleidoscope 5.1

Using the new Kaleidoscope 5.1 and a little diffTool configuration for SnapshortTesting, you instead get a clickable link within Xcode:

One single click and you immediately see what went wrong in the test:

Kaleidoscope showing the two images of a failed snapshot test. The previously recorded snapshot in A and the failed test in B. Not that both images are named snapshot and failed instead of using an arbitrary file name.

This is all code that was required in our test file to define Kaleidoscope as a new diffTool, using the URL scheme:

The URL scheme

Now that we have seen a use case, let’s look at what the URL scheme hast to offer. The basic form of a URL recognized by Kaleidoscope is very simple:

kaleidoscope://<command>?<arguments>

Commands

compare | diffThe compare and diff commands are interchangeable and open the files specified in parameters in a comparison.
clipboard | pasteboardAdd the contents of the macOS clipboard to a comparison. Use the label parameter to specify a destination document.
historyThe history command requires a single file in parameters. In case the file specified is inside a git working directory, Kaleidoscope will open the Git File History for that file.
changesetThis command will try to open the changeset for the git commit identifier provided in arguments.

Arguments

Arguments supply the content to be used with a command and control overall behavior. Parameters are separated by the & character.

labelThe label parameter is a key=value parameter in the form label=<string>. When supplied, the value of <string> will be used as title of the document. This is useful for repeatedly sending content to the same document as before.
filesFile paths can be provided in one of two formats:
– As pure file path. Paths can be either absolute or use ~ to reference the user home directory. An absolute path starts with /.
– As key/values pair. Here, key will be used to name the file in Kaleidoscope. This is particularly helpful when the file path is not self-explanatory, such as when supplying files generated by a tool that automatically names files. For the path itself, see above.
commit identifierProvide a git commit identifier for the changeset command. This can be either full 40-character commit hash or one shortened to 8 characters.
Note that the repository containing the commit needs to be in the Repositories list of Kaleidoscope for this to work.

Note that strings and paths supplied as parameters need to be URL encoded, e.g., if a file path contains a space character, it needs to be encoded as %20 in the parameter.