简体   繁体   English

作为命令在AppleScript中复制串联

[英]Copy Concatenation in AppleScript as a command

so I have a quick question for anyone willing to help. 所以我有一个快速的问题要问愿意帮助的人。 When I am programming in a regular text editor, I often find myself wanting to copy multiple lines of code, concatenating them on the fly and then being able to paste their contents just like I would normally use Command+c/Command+v. 在常规文本编辑器中编程时,我经常发现自己想要复制多行代码,即时将它们连接起来,然后能够像通常使用Command + c / Command + v一样粘贴其内容。

I think this would be done in Applescript and then assigned a custom shortcut with Quicksilver but I am not too familiar with either. 我认为这可以在Applescript中完成,然后使用Quicksilver分配自定义快捷方式,但是我都不是很熟悉。 Below is an example to illustrate the desired behavior. 下面是一个示例,以说明所需的行为。

Copy-Concatenate with Command+C+X  Paste with Command+V  Clear Clipboard when regular Command+C is used

so...
Command+C+X "First line" ... Command+C+x"Second line" ... Command+V pastes "First lineSecond line"
and Command+C"Third line"... Command+V pastes "Third line"

Can someone help me accomplish this or set me on the right path? 有人可以帮助我完成此任务,还是让我走上正确的道路? Thank you in advance. 先感谢您。

Select the text in your editor and try this: 在编辑器中选择文本,然后尝试以下操作:

tell application "System Events" to keystroke "x" using command down
set myText to the clipboard as «class utf8»
set {TID, text item delimiters} to {text item delimiters, {return, linefeed, character id 8233, character id 8232}}
set myText to text items of myText
set AppleScript's text item delimiters to space
set the clipboard to myText as text
set text item delimiters to TID
tell application "System Events" to keystroke "v" using command down

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

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