Эти функции отсутствуют в современных версиях R (IIRC они возвращаются к временам до MacOS / Mac OS X).
Однако функция applescript()
не выполняла никаких действий:
applescript <- function(script_source, extra_args = c()) {
script_source <- paste0(script_source, collapse = "\n")
tf <- tempfile(fileext = ".applescript")
on.exit(unlink(tf), add=TRUE)
cat(script_source, file = tf)
osascript <- Sys.which("osascript")
args <- c(extra_args, tf)
system2(
command = osascript,
args = args,
stdout = TRUE
) -> res
invisible(res)
}
Таким образом, вы можете делать с ней все что угодно, например, открывать папку:
applescript(
sprintf(
'tell app "Finder" to open POSIX file "%s"',
Sys.getenv("R_DOC_DIR")
)
)
или,запросить приложение и вернуть данные:
res <- applescript('
tell application "iTunes"
set r_name to name of current track
set r_artist to artist of current track
end
return "artist=" & r_artist & "\ntrack=" & r_name
')
print(res)
## [1] "artist=NICO Touches the Walls" "track=Hologram"
Для (mebbe) более легкого использования (я говорю «mebbe», поскольку pkg для некоторых вещей полагается на reticulate
) Я добавил это к macthekinfe
MacOS-ориентированный пакет R.