简体   繁体   English

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

[英]AppleScript adds Enter/NewLine to clipboard when paste into Word

I'm currently trying to write an AppleScript for my Touchbar, which does copy a predefined variable into the clipboard and then pastes it into a word document. 我正在尝试为Touchbar编写AppleScript,它会将预定义的变量复制到剪贴板中,然后将其粘贴到word文档中。

Well, it does work, but for some reason in addition of just pasting the variable text, it also adds a Enter/NewLine to it. 嗯,它确实有效,但由于某些原因,除了粘贴变量文本之外,它还为它添加了一个Enter / NewLine。 Now I already did some testing and just assigned plain text directly to the clipboard and the NewLine was still there, so it isn't the variable. 现在我已经做了一些测试,只是将纯文本直接分配给剪贴板,而NewLine仍然存在,所以它不是变量。 I also tested the Cmd+V output and also when I just paste the text manually afterwards it still pastes it with an enter, so it seems like there is something wrong with the assignment. 我还测试了Cmd + V输出,当我手动粘贴文本后,它仍然用输入粘贴它,所以看起来分配有问题。 But since I'm new to AppleScript and the language is really weird, I don't really get what I'm doing wrong here. 但是因为我是AppleScript的新手并且语言真的很奇怪,所以我真的不知道我在这里做错了什么。 Here is the important code part: 这是重要的代码部分:

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}

Now I just noticed that when I let AppleScript paste into Pages, TextEdit or straight into the code, it doesn't include a NewLine. 现在我注意到,当我将AppleScript粘贴到Pages,TextEdit或直接插入代码时,它不包含NewLine。 Any Ideas? 有任何想法吗?

It must be something that Word is doing with it's "Smart Cut & Paste" options, though I'm not seeing that behavior in Word 2011. You can look to alter that behavior in the advanced Advanced settings. 它必须是Word正在使用它的“智能剪切和粘贴”选项,尽管我在Word 2011中没有看到这种行为。您可以在高级高级设置中查看更改该行为。 You can also just alter your script to delete the paragraph marker when you're pasting into Word. 您也可以更改脚本以在粘贴到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

You can use the type text command of Microsoft Word . 您可以使用Microsoft Wordtype text命令。

set Donnerstag12 to "Anwendungsentwicklung"
tell application "Microsoft Word" to type text selection text Donnerstag12

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM