如何解决当您将其复制到剪贴板时,macOS会更改文本 AppleScript: Shell脚本将输入传递到stdin:
我有一些文字
blah blah blah
this is a new line
blah blah blah
我希望能够复制上面的文本,粘贴时,我希望它看起来像这样
blah blah blah<br>this is a new line<br>blah blah blah
您如何在macOS中执行此操作?自动化? Applescript?
解决方法
另一个:
set theText to "blah blah blah
this is a new line
blah blah blah"
set curTID to AppleScript's text item delimiters
set theText to every paragraph of theText
set AppleScript's text item delimiters to "<br>"
set theText to theText as text
set AppleScript's text item delimiters to curTID
return theText
,
以下示例 AppleScript 代码显示了一种操作文本的方式您的OP:
set theText to "blah blah blah
this is a new line
blah blah blah"
set curTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {linefeed,return}
set theText to text items of theText
set AppleScript's text item delimiters to "<br>"
set theText to theText as text
set AppleScript's text item delimiters to curTID
return theText
结果:
"blah blah blah<br>this is a new line<br>blah blah blah"
您可以将其合并到 Automator 服务/快速操作中的运行AppleScript 操作中,是你想要的。
,您可能需要创建一个Automator Service工作流程,然后可以通过“系统偏好设置”将键盘快捷键绑定到该工作流程。在工作流程中,您可以插入运行AppleScript 操作或运行Shell脚本操作。删除任何现有的示例代码,然后插入以下代码之一(取决于您选择的操作):
AppleScript:
on run {input}
set my text item delimiters to "<br>"
return the input's paragraphs as text
end run
Shell脚本将输入传递到stdin:
input="$(</dev/stdin)"
printf "${input//$'\n'/<br>}"
您将需要勾选 输出替换所选文本 复选框。要选择工作流应接收的内容,请确定您设想激活此服务的两种方案中的哪一种:
-
如果服务应在突出显示的文本上运行,然后将其替换为修改后的输出,请选择 工作流接收:文本
-
如果服务应该对剪贴板上存储的文本进行操作,然后将其插入您当前正在处理的文档中,请选择 工作流接收:无输入 。另外,在运行AppleScript 或运行Shell脚本操作上方插入名为获取剪贴板内容的操作。
将服务保存为您希望其显示在服务菜单中的任何内容。通过系统偏好设置分配键盘快捷键(例如 ⌃ V )。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。