AppleScript在粘贴到Word时将Enter / NewLine添加到剪贴板

时间:2017-02-01 19:02:10

标签: ms-word applescript newline clipboard enter

我目前正在尝试为我的Touchbar编写AppleScript,它会将预定义的变量复制到剪贴板中,然后将其粘贴到word文档中。

嗯,它确实有效,但由于某些原因,除了粘贴变量文本之外,它还为它添加了一个Enter / NewLine。 现在我已经做了一些测试,只是将纯文本直接分配给剪贴板,NewLine仍然存在,所以它不是变量。我还测试了Cmd + V输出,当我手动粘贴文本后,它仍然用输入粘贴它,所以看起来分配有问题。但是因为我是AppleScript的新手并且语言非常奇怪,所以我不会真正理解我在这里做错了什么。以下是重要的代码部分:

activate application "Microsoft Word" --I'm doing this, but you prolly don't need to.
set Donnerstag12 to "Anwendungsentwicklung"
set the clipboard to Donnerstag12
tell application "System Events" to keystroke "v" using {command down}

现在我注意到,当我将AppleScript粘贴到Pages,TextEdit或直接插入代码时,它并没有包含NewLine。任何想法?

2 个答案:

答案 0 :(得分:0)

它必须是Word正在使用它的“Smart Cut& Paste”选项,尽管我在Word 2011中没有看到这种行为。您可以在高级高级设置中查看更改该行为。您也可以在粘贴到Word时更改脚本以删除段落标记。

activate application "Microsoft Word" --I'm doing this, but you prolly don't need to.
set Donnerstag12 to "Anwendungsentwicklung"
set the clipboard to Donnerstag12
tell application "System Events"
    keystroke "v" using {command down}
    if name of (first process whose frontmost is true) is "Microsoft Word" then key code 51
end tell

答案 1 :(得分:0)

您可以使用 Microsoft Word <div class="container"> <p>Please dont feed the gold fish, they will turn into gremlins</p> </div> 命令。

type text
相关问题