Skip to content

Instantly share code, notes, and snippets.

@mpjdem
Last active July 29, 2019 23:44
Show Gist options
  • Save mpjdem/10a7dd33ced93f7995ed8c8980b4fc73 to your computer and use it in GitHub Desktop.
Save mpjdem/10a7dd33ced93f7995ed8c8980b4fc73 to your computer and use it in GitHub Desktop.
Take a screenshot of your RStudio window in Linux
rstudio_screenshot <- function(partial_name = "") {
look_behind <- "(?<=\\s)"
xwid_pattern <- "0x[a-f0-9]+"
look_ahead <-
paste0("(?=\\s\".*",
partial_name,
".*\":\\s\\(\"rstudio\"\\s\"RStudio\"\\)\\s+[0-9]{4}x[0-9]{3,4})")
xwid <-
system(paste0("xwininfo -tree -root |",
"grep -oP '", look_behind, xwid_pattern, look_ahead, "' |",
"head -n 1"),
intern = TRUE)
stopifnot(is.character(xwid) && length(xwid) == 1)
cat(paste0("Taking screenshot of window ", xwid))
magick::image_write(magick::image_read(paste0("x:", xwid)),
path = format(Sys.time(), "RStudio-%Y%m%d-%H%M%S.png"),
format = "png")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment