applescript: Execute AppleScript and Return Results

Description Usage Arguments Value Note Examples

View source: R/applescript.R

Description

Execute AppleScript and Return Results

Usage

1
applescript(script_source, extra_args = c(), params = c())

Arguments

script_source

character vector of valid applescript source lines. They will be turned into a single script file with a newline inserted between each element of the vector.

extra_args

the applescript binary takes arguments but we only use the filename execution so you can place any other arguments for it here. NOTE that there is a separate parameter for specifying parameters

param

a character vector of parameters to pass to the invokation.

Value

anything the script returns (invisibly).

Note

stdout is captured and returned but stderr (if any) is displayed in the console.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
## Not run: 
# open a folder
applescript(
  sprintf(
    'tell app "Finder" to open POSIX file "%s"',
    Sys.getenv("R_DOC_DIR")
  )
)


# talk to an app and return data
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 & " || track=" & r_name
')

print(res)

## End(Not run)

hrbrmstr/mactheknife documentation built on Nov. 5, 2018, 5:23 p.m.