library(tidyverse) omnijs <- function(cmd, wait = 0.10) { browseURL( sprintf("omnigraffle:///omnijs-run?script=%s", URLencode(cmd)) ) } omni_schema_src <- function(src) { db_tbls <- src_tbls(src) start <- 0 max_len <- 0 sz <- 9 space_over <- 10 * sz map_chr(db_tbls, function(tbl_name) { suppressWarnings( tbl(src, tbl_name) %>% head(1) %>% collect() %>% as.data.frame() %>% summarise_all(pillar::new_pillar_type) %>% gather(variable, class) -> schema ) rows <- as.character(glue::glue('{schema$variable} <{schema$class}>')) map_chr(1:nrow(schema), ~{ as.character(glue::glue("\ntable.graphicAt({.x}, 0).text = '{rows[.x]}'\n")) }) %>% paste0(collapse = "\n") -> sch if (start != 0) start <<- start + space_over max_len <<- max(nchar(rows)) glue::glue(" cnvs = document.windows[0].selection.canvas rect = new Rect({start}, 0, {max_len} * {sz}, 26) graphic = cnvs.addShape('Rectangle', rect) // graphic properties graphic.strokeThickness = 0.25 graphic.strokeColor = Color.black // solid properties graphic.fillColor = Color.white graphic.fillType = FillType.Solid // solid text properties graphic.text = '' graphic.textSize = 12 graphic.textColor = Color.black graphic.textHorizontalAlignment = HorizontalTextAlignment.Left graphic.textVerticalPlacement = VerticalTextPlacement.Middle graphic.fontName = 'Monaco' graphic.textHorizontalPadding = 10 graphic.textVerticalPadding = 0 // create the base table table = new Table(graphic) table.columns = 1 table.rows = {nrow(schema) + 1} // adjust header row and column size table.setRowHeight(36, 0) table.graphicAt(0, 0).text = '{tbl_name}' table.graphicAt(0, 0).textHorizontalAlignment = HorizontalTextAlignment.Center table.graphicAt(0, 0).fillColor = Color.black table.graphicAt(0, 0).textColor = Color.white table.graphicAt(0, 0).textSize = 14 {sch} ") %>% as.character() -> out start <<- start + (max_len * sz) out }) -> schema_out omnijs(paste0(schema_out, collapse = "\n\n")) } src_sqlite("~/Library/Application Support/Knowledge/knowledgeC.db") %>% omni_schema_src()