xcode添加代码块注释并添加自定义快捷键 macOS

使用apple script实现,使用automator工具--快速操作--运行applescript

on run {input, parameters}

    return "/*
" & (input as string) & "
*/"

end run
--进阶版:
--按一下是块状注释,再按一下是取消块注释
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

xcode添加代码块注释并添加自定义快捷键 macOS_第1张图片

保存名为block comment,然后设置在键盘--服务--中设置快捷键

xcode添加代码块注释并添加自定义快捷键 macOS_第2张图片

 此方法不仅适用于xcode,也适用于python等任何编辑器

你可能感兴趣的:(python,xcode,macos,ios)