Obtendo a tabela atual em números (Python/Appscript)
Pergunta
Como faço para acessar a tabela atual em números usando py-appscript
?
Para a posteridade, o programa que criei usando essas informações limpa todas as células da tabela atual e retorna a seleção para a célula A1
. Transformei -o em um serviço usando um script de shell python run no Automator e anexei -o aos números.
from appscript import *
Numbers = app('Numbers')
current_table = None
for sheet in Numbers.documents.first.sheets():
for table in sheet.tables():
if table.selection_range():
current_table = table
if current_table:
for cell in current_table.cells():
cell.value.set('')
current_table.selection_range.set(to=current_table.ranges[u'A1'])
Foi usado para limpar grandes tabelas de números que eu usei para cálculos temporários.
Solução
>>> d = app('Numbers').documents.first() # reference to current top document
EDIT: Não parece haver uma única referência direta para a tabela atual, mas parece que você pode encontrá-la pesquisando as folhas atuais do primeiro documento para uma tabela com uma seleção não nula, então algo assim:
>>> nu = app('Numbers')
>>> for sheet in nu.documents.first.sheets():
... for table in sheet.tables():
... if table.selection_range():
... print table.name()
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow