编辑剪贴板中的内容与AppleScript的在OS X中 [英] Edit clipboard content with applescript in os x

查看:2095
本文介绍了编辑剪贴板中的内容与AppleScript的在OS X中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我复制了很多源$ C ​​$ C从不同的项目给别人,我总是不得不改变相同的条款。是否有可能使用的检查剪贴板中的文本内容,并取代了几个关键字的AppleScript?我是新来的AppleScript所以我不知道强大的AppleScript怎么可以......

I'm copying a lot of source code from different projects to others and I always have to change the same terms. Is it possible to use an applescript which checks the text-content of the clipboard and replaces several keyword? I'm new to applescript so I'm not aware of how powerful applescript can be...

推荐答案

这是可以使用获取剪贴板设置剪贴板和文本项分隔符。

This is possible using get clipboard, set clipboard, and the text item delimiters.

get the clipboard
set the clipboard to (replacement of "this text" by "that text" for the result)

on replacement of oldDelim by newDelim for sourceString
    set oldTIDs to text item delimiters of AppleScript
    set text item delimiters of AppleScript to oldDelim
    set strtoks to text items of sourceString
    set text item delimiters of AppleScript to newDelim
    set joinedString to strtoks as string
    set text item delimiters of AppleScript to oldTIDs
    joinedString
end replacement

对于更复杂的文本操作,我只是调出一个shell脚本。以上变为:

For more sophisticated text manipulation, I'd just call out to a shell script. The above becomes:

do shell script "pbpaste | sed 's/this text/that text/g' | pbcopy"

这篇关于编辑剪贴板中的内容与AppleScript的在OS X中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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