使用 Applescript 在 Numbers 表格中的文本项目中创建超链接

问题描述 投票:0回答:1

我无法将

text item
(iWork 容器)设为超链接。使用 GUI 执行的等效操作是:

  • 添加文本容器
  • 修改文字
  • 选择文本容器,右键单击并选择“添加链接”

我成功地使用 Applescript 和 Numbers 在单元格值中创建超链接。为此,我将单元格值设置为

=hyperlink(url,text)
函数。但是,我不想创建一个新表来插入超链接。

我使用 Applescript Numbers Dictionary 来查找 iWork 容器超链接的任何引用,但找不到任何内容。

hyperlink numbers applescript
1个回答
0
投票

我找到的解决方案意味着通过向应用程序发送击键来创建链接来操作 Numbers UI。

tell application "Numbers"
    set myDocument to open POSIX file "/path/to/my/doc.numbers"
    tell myDocument
        activate -- required in order to receive keystrokes in Numbers
        tell sheet 1
            set myText to make text item
            set object text of myText to "Hello World"
            tell application "System Events" to keystroke "a" using command down -- select all the text
            tell application "System Events" to keystroke "k" using command down -- add a link
            tell application "System Events" to keystroke "https://mylink" -- input the link
            tell application "System Events" to keystroke return using command down -- close the link dialog box
        end tell
    end tell
end tell
© www.soinside.com 2019 - 2024. All rights reserved.