【发布时间】:2020-10-18 01:08:31
【问题描述】:
我是 MacOS 独立应用程序开发的新手,我正在努力解决现有应用程序中的问题。我们的应用程序访问 Microsoft Word 文档并通过 AppleScript 将文本插入到 Word 文档中。当我运行应用程序并通过 XCode 执行插入操作时,文本没有插入到 Word 文档中。它早些时候运行良好,但从过去几天开始,文本没有插入到 Word 文档中
在 XCode 中使用以下代码将文本复制到粘贴板,然后调用 AppeScript 将文本插入到 Word 文档中
NSPasteboard * pasteboard = [NSPasteboard generalPasteboard];
[pasteboard clearContents];
[pasteboard writeObjects:@[textToInsert]];
以下是用于将文本插入 Word 文档的 AppleScript
on insertSampleText()
try
using terms from application "Microsoft Word"
tell application "Microsoft Word"
activate
tell application "System Events"
keystroke "v" using {command down}
end tell
end tell
end using terms from
return "0"
on error the error_message number the error_number
set the error_text to "" & the error_number
return the error_text
end try
end insertSampleText
您能否建议将文本插入 Word 文档需要做什么?
【问题讨论】:
标签: xcode ms-word macos-mojave applescript-objc