使用 AppleScript 从剪贴板复制纯文本 [英] Copy pure text from clipboard using AppleScript

查看:46
本文介绍了使用 AppleScript 从剪贴板复制纯文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况

  • 打开一个 Word 文档.
  • 将文档内部的一些格式化文本复制到剪贴板.
  • 将其粘贴到 CKEditor
  • 的实例中

CKEditor 收到了带有大量无用 html 元素和样式的 M$ 风格的 HTML.即使使用 CKEditor 的功能删除格式也不会呈现纯文本.

CKEditor received smelling M$-style HTML with tons of useless html elements and styles. Even removing formatting using CKEditor's feature does not render pure text.

所需的解决方案

谁能提供一个 AppleScript,它会删除样式化/HTML 字符串并将纯文本部分粘贴回剪贴板.

Could anybody provide an AppleScript, which removes the styled-/HTML-string and pastes the pure text part back to clipboard.

加号是一个简短的提示,如何将 AppleScript 绑定到功能键.

A plus would be a short hint, how to bind the AppleScript to function key.

推荐答案

您没有显示您当前的复制和粘贴方式.不过,应该可以使用这样的东西:

You don't show how you're copying and pasting currently. It should be possible to use something like this, though:

tell application "Word"
    set theData to (the clipboard as text)
    set the clipboard to theData
end tell

这将获得剪贴板数据的纯文本版本,然后用纯文本替换剪贴板内容(包含 HTML).

That will obtain the plain text version of the clipboard data and then replace the clipboard contents (which contains HTML) with the plain text.

要将脚本绑定到功能键,我建议使用 Automator 制作一个运行脚本的服务,然后使用系统偏好设置的键盘面板分配一个键.事实上,我怀疑这整个任务作为接收文本作为输入的服务会更好,而不是尝试从剪贴板中明确获取它.

To bind the script to a function key, I recommend using Automator to make a service that runs your script and then use the Keyboard pane of System Preferences to assign a key. In fact, I suspect this whole task would be better as a service that receives the text as input rather than attempting to explicitly fetch it from the clipboard.

这篇关于使用 AppleScript 从剪贴板复制纯文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆