You are not logged in.
Pages:: 1
When Keynote has more than one table, there appears to be no way to manipulate any table other than the first one.
Applescript:
activate application "Keynote"
tell application "Keynote"
tell the front document
tell the current slide
set tableCount to count of its tables
set auction to its last table
tell auction
set getName to its name
end tell
tableCount & getName
end tell
end tell
end tell
This returns {2, "Table 1"}
Any operations on the slide's "Table 2" or "last table" apply only to the first table. Is there any way around this?
Model: Mini 5,3
AppleScript: 2.7
Browser: Safari 605.1.15
Operating System: macOS 10.13
Last edited by 4CardsMan (2021-03-26 03:03:22 am)
Offline
Hi 4CardsMan.
A belated reply, but the name of a table mustn't be confused with its index in the slide's collection of tables. (The same applies with the names of tables and sheets in the Numbers application.)
I can reproduce your situation by adding a table to a table-less slide, changing the table's default name from "Table 1" to something else ("Fred", say), and then adding a second table. The second table will also take the name "Table 1", since that name's not in use at the time it's created. But it's still the second table in the slide:
Applescript:
tell application "Keynote"
tell the front document
tell the current slide
get {name of table 1, name of table 2} --> {"Fred", "Table 1"}
end tell
end tell
end tell
It may be too that subsequent edits will change the order of tables within a slide, but I can't vouch for this.
I don't know if any of the above is true for your tables, but confusion between the name "Table 1" and the specifier table 1 is something that's come up before.
NG
Offline
tell application "Keynote"
activate
tell the front document
tell the current slide
set theTable to its last table
end tell
end tell
end tell
returns this:
table 4 of slide 121 of document id "943898A4-EFC7-4A31-A76E-7D9C56A83252" of application "Keynote"
going further,
tell application "Keynote"
activate
tell the front document
tell the current slide
set theTable to its last table
tell theTable
its name
end tell
end tell
end tell
end tell
returns
"Table 3"
After more poking around, it appears that a calling a specific table number returns the table requested minus one. Calling the first table returns "Table 4". This seems a little strange, but it is workable.
Offline
Sometimes when we need a specific object there are other options.
In your case we could use position. In other words if you have 4 table in your slide.
You could ask for the position of whose and set if statement to the one you are interesting in.
And this code could maybe be done without repeat loop.
ex.
Applescript:
tableNameByPosition({109, 74})
on tableNameByPosition(thePosition)
tell application "Keynote"
tell front document to tell current slide
set theTables to every table
end tell
repeat with t in theTables
if (position of t = thePosition as list) then
-- do something
tell t to set theName to its name
end if
end repeat
try
return theName
end try
end tell
end tableNameByPosition
And without repeat loop
Applescript:
on tableNameByPosition(thePosition)
tell application "Keynote" to tell front document to tell current slide to set theName to name of every table whose position is thePosition
return theName as text
end tableNameByPosition
Here is also with error checking
Applescript:
on tableNameByPosition(thePosition)
tell application "Keynote" to tell front document to tell current slide to set theName to name of every table whose position is (thePosition as list)
if (theName is {}) then return "Error: Position value is incorrect!"
return theName as text
end tableNameByPosition
The first script is slower and the second one.
Last edited by Fredrik71 (2021-04-07 04:17:42 am)
if you are the expert, who will you call if its not your imagination.
Offline
Pages:: 1