参考: stackoverflow
使用Automator
创建service
- 打开Automator, 选择 Quick Action
- 勾选 Output replaces selected text
- 在左侧Library搜索 AppleScript, 双击
Run AppleScript
- 代码如下:
on run {input, parameters}
repeat with anInput in input
if "/*" is in anInput then
set input to replaceText("/*", "", input as string)
set input to replaceText("*/", "", input as string)
return input
exit repeat
end if
end repeat
return "/*" & (input as string) & "*/"
end run
on replaceText(find, replace, textString)
set prevTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to find
set textString to text items of textString
set AppleScript's text item delimiters to replace
set textString to "" & textString
set AppleScript's text item delimiters to prevTIDs
return textString
end replaceText
- 运行,保存,名为Block Comment
此时在xcode 已经可以使用该服务:
在 system preferences中为服务添加快捷键
自此可以使用快捷键注释选中的文本。