要解决Automator添加不需要的换行符的问题,你可以使用AppleScript来处理文本并删除多余的换行符。
以下是一个示例代码,它将使用AppleScript来去除文本中的多余换行符:
on run {input, parameters}
set output to {}
repeat with i from 1 to count of input
set currentText to item i of input
set cleanedText to my removeExtraLineBreaks(currentText)
set end of output to cleanedText
end repeat
return output
end run
on removeExtraLineBreaks(textString)
set AppleScript's text item delimiters to {return & linefeed, return, linefeed}
set textList to text items of textString
set AppleScript's text item delimiters to ""
set cleanedText to textList as string
return cleanedText
end removeExtraLineBreaks
你可以将这个代码保存为一个AppleScript文件,然后在Automator工作流中使用"Run AppleScript"操作来调用该脚本。
这个示例代码会遍历输入的文本,将每个文本都传递给removeExtraLineBreaks
函数进行处理。removeExtraLineBreaks
函数使用AppleScript的文本项分隔符来拆分文本,并将拆分后的文本再次组合成一个字符串,从而去除多余的换行符。
注意:这个示例代码只处理了回车(return)和换行(linefeed)字符,如果你的文本中包含其他特殊字符,你可能需要根据需要进行调整。