Here’s an example AppleScript script that transforms the data from a single selected row or column in a Numbers table to a pie chart on a new slide in Keynote.
DO THIS ►DOWNLOAD the simple example Numbers document.
Simply select a single row or column in a Numbers table and run the script. The row data will be extracted and used to create a pie chart on a new slide in the frontmost Keynote document. In addition, the name of the selected table can optionally be used as the title for the created slide.
New Pie Chart in Keynote using Data From Selected Column | Row
01
propertyuseTableNameForslideTitle : false
02
03
tellapplication "Numbers"
04
activate
05
try
06
-- check for document
07
if not (existsdocument 1) then errornumber 1000
08
telldocument 1
09
try -- check for selected table
10
tellactive sheet
11
set theselectedTableto ¬
12
(the firsttablewhoseclassofselection rangeisrange)
13
end tell
14
on error
15
errornumber 1001
16
end try
17
tellselectedTable
18
setthisTableNameto itsname
19
-- get the count fo the various headers and footers
20
set theheadercolumnCounttoheader column count
21
set theheaderrowCounttoheader row count
22
set thefooterrowCounttofooter row count
23
-- store references to the intersecting columns and rows
24
settheseRowsto therowsof theselection range
25
settheseColumnsto thecolumnsof theselection range
26
-- get the row and column counts
27
setrowCountto (countoftheseRows)
28
setcolumnCountto (countoftheseColumns)
29
-- check for errors
30
if (rowCountis not 1) and (columnCountis not 1) then
31
errornumber 1002
32
else if (rowCountis 1) and (columnCountis 1) then
33
errornumber 1002
34
end if
35
ifheaderrowCountis greater than 1 then
36
errornumber 1003
37
end if
38
ifheadercolumnCountis greater than 1 then
39
errornumber 1004
40
end if
41
-- get the column names
42
setcolumnNamesto {}
43
ifheadercolumnCountis not 0 then
44
repeat withifrom 1 to thecountoftheseColumns
45
setthisValueto (thevalueof the firstcellof (itemioftheseColumns))
46
ifthisValueis notmissing valuethen
47
set the end ofcolumnNamestothisValue
48
end if
49
end repeat
50
end if
51
-- get the row names
52
setrowNamesto {}
53
ifheaderrowCountis not 0 then
54
repeat withifrom 1 to thecountoftheseRows
55
setthisValueto (thevalueof the firstcellof (itemioftheseRows))
56
ifthisValueis notmissing valuethen
57
set the end ofrowNamestothisValue
58
end if
59
end repeat
60
end if
61
end tell
62
-- add the chart to a new slide inserted after the current slide
In macOS Mojave v10.14 Automator workflows can be saved as “Quick Actions” for the MacBook Touch Bar. The previous script can be adapted for use as a Touch Bar item.
DO THIS ►DOWNLOAD the Automator service workflow for macOS Mojave.
The following video shows the “Pie in Keynote” Touch Bar Quick Action in use:
DOWNLOAD an example Numbers document containing a more complex table.
DISCLAIMER
THIS WEBSITE IS NOT HOSTED BY APPLE INC.
Mention of third-party websites and products is for informational purposes only and constitutes neither an endorsement nor a recommendation. MACOSXAUTOMATION.COM assumes no responsibility with regard to the selection, performance or use of information or products found at third-party websites. MACOSXAUTOMATION.COM provides this only as a convenience to our users. MACOSXAUTOMATION.COM has not tested the information found on these sites and makes no representations regarding its accuracy or reliability. There are risks inherent in the use of any information or products found on the Internet, and MACOSXAUTOMATION.COM assumes no responsibility in this regard. Please understand that a third-party site is independent from MACOSXAUTOMATION.COM and that MACOSXAUTOMATION.COM has no control over the content on that website. Please contact the vendor for additional information.