获取当前表格(Python/AppScript)
题
如何使用 py-appscript
?
对于后代,我使用此信息创建的程序清除了当前表的所有单元格,并将选择返回到单元格 A1
. 。我使用Automator中的Python Run Shell脚本将其变成了服务,并将其附加到数字上。
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'])
它用于清除我用于临时计算的数字。
解决方案
>>> d = app('Numbers').documents.first() # reference to current top document
编辑:似乎没有直接向当前表的单一引用,但是您可以通过搜索具有非null selection_range的表格来找到它,从而找到它,所以类似的东西:
>>> nu = app('Numbers')
>>> for sheet in nu.documents.first.sheets():
... for table in sheet.tables():
... if table.selection_range():
... print table.name()
不隶属于 StackOverflow