OmniGraffle + Powerpoint = Editable Individual Objects

Here’s some Omni Automation code for exporting your current selection. (You could export a list of arbitrary shapes instead, this code just happens to be grabbing the shapes to export from the selection.)

(async () => {
    let exportDocumentToPasteboardAsType = (async (document, exportType) => {
        console.log(`DEBUG: Copying ${exportType} to the pasteboard from ${document}`);
        let wrapper = await document.makeFileWrapper("export.data", exportType.identifier);
        let data = wrapper.contents;
        let pasteboard = Pasteboard.general;
        pasteboard.clear();
        pasteboard.setDataForType(data, exportType);
        console.log(`DEBUG: Copied ${exportType} to the pasteboard (${data.length} bytes), resulting in ${pasteboard.types}`);
        // console.log(`DEBUG: Base-64 data: ${data.toBase64()}`)
    });

    let copySelectionToNewDocument = (async (selection) => {
        let newDocument = await Document.makeNew();
        let newCanvas = newDocument.portfolio.canvases[0];
        let copiedGraphics = newCanvas.duplicate(selection.graphics);
        newCanvas.canvasSizingMode = CanvasSizingMode.Fit;

        console.log(`DEBUG: Copied selected graphics to new document ${newDocument}, canvas size ${newCanvas.size}`);

        return newDocument;
    });

    let exportSelectionToPasteboardAsType = (async (selection, exportType) => {
        let newDocument = await copySelectionToNewDocument(selection);
        await exportDocumentToPasteboardAsType(newDocument, exportType);
        newDocument.close();
    });

    try {
        await exportSelectionToPasteboardAsType(document.windows[0].selection, TypeIdentifier.png);
        // let svgType = new TypeIdentifier("public.svg-image");
        // await exportSelectionToPasteboardAsType(document.windows[0].selection, svgType);
    } catch (e) {
        console.log(`Caught error: ${e}`);
    }

})();

Caveat: The reason for the commented-out log of the data in base-64 format is because the pasteboard accepts the public.svg-image format (as we can see from the types it makes savailable), but then apparently tries to convert it to other possible formats and ends up losing track of it in the process. So because of that system bug (tested on macOS Monterey version 12.0.1) it doesn’t actually work to send that content to the pasteboard using that type identifier. (This could be modified to write the SVG to the pasteboard as plain text instead by just swapping in TypeIdentifier.plainText.identifier in the call to setDataForType(). Or perhaps write it to a temporary file, then copy that file to the pasteboard? Or just use that file directly, for wherever this data is headed next.)

Exporting in PNG format (as the code currently does, specifying TypeIdentifier.png) works fine. As does PDF format (use TypeIdentifier.pdf instead).

2 Likes