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

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

问题描述

情况

  • 打开Word文档.
  • 将某些格式的文本从文档内部复制到剪贴板.
  • 将其粘贴到 CKEditor
  • 的实例中
  • Open a Word Document.
  • Copy some formatted text from inside the document to the clipboard.
  • Paste it into an instance of 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,该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天全站免登陆