Copying System Clipboard as Styled Text Converts It to Plain Text

Any application developer can define their own pasteboard types, and give them a string name, for example:

  • com.stairways.keyboardmaestro.macrogroupsarray
  • com.stairways.keyboardmaestro.macrogroupuidsarray

but the built-in types of data (KM "flavors") that the clipboard can hold are listed at:

Their direct name strings are:

public.url
com.apple.cocoa.pasteboard.color
public.file-url
com.apple.cocoa.pasteboard.character-formatting
public.html
com.apple.cocoa.pasteboard.multiple-text-selection
com.adobe.pdf
public.png
public.rtf
com.apple.flat-rtfd
com.apple.cocoa.pasteboard.paragraph-formatting
com.apple.cocoa.pasteboard.sound
public.utf8-plain-text
public.utf8-tab-separated-values-text
com.apple.cocoa.pasteboard.find-panel-search-options
public.tiff

which you can derive, in an Execute JavaScript for Automation action with:

Built-in pasteboard types.kmmacros (2.3 KB)


Expand disclosure triangle to view JS source
ObjC.import("AppKit");

const uw = ObjC.unwrap;

const systemFlavors = `NSPasteboardTypeURL
NSPasteboardTypeColor
NSPasteboardTypeFileURL
NSPasteboardTypeFont
NSPasteboardTypeHTML
NSPasteboardTypeMultipleTextSelection
NSPasteboardTypePDF
NSPasteboardTypePNG
NSPasteboardTypeRTF
NSPasteboardTypeRTFD
NSPasteboardTypeRuler
NSPasteboardTypeSound
NSPasteboardTypeString
NSPasteboardTypeTabularText
NSPasteboardTypeTextFinderOptions
NSPasteboardTypeTIFF`;

systemFlavors
    .split("\n")
    .map(k => uw($[k]))
    .join("\n");

The key points to understand are that:

  1. Any application from which we copy can place several different pasteboard types (KM "flavours") in the clipboard at the same time, and
  2. the application into which we paste looks to see which "flavours" the clipboard contains, and selects one of them to use.
  3. We can sometimes override an application's default choice of which flavour to use, by deleting any competing flavours from the clipboard.
3 Likes