问题是HTML 代码 (Automator/AppleScript) 的纯文本 URL的续集。
假设我有一个纯 txt 文件 /Users/myname/Desktop/URLlist.txt:
title 1
http://a.b/c
title 2
http://d.e/f
...
我想 (1) 将所有 URL ( http://.. .) 转换为 HTML 代码,并且 (2) 添加
<br />
到每个空行,这样前面提到的内容就变成了:
title 1
<a href="http://a.b/c">http://a.b/c</a>
<br />
title 2
<a href="http://d.e/f">http://d.e/f</a>
<br />
...
我来到以下Applescript:
set inFile to "/Users/myname/Desktop/URLlist.txt"
set middleFile to "/Users/myname/Desktop/URLlist2.txt"
set outFile to "/Users/myname/Desktop/URLlist3.txt"
do shell script "sed 's/\\(http[^ ]*\\)/<a href=\"\\1\">\\1<\\/a>/g' " & quoted form of inFile & " >" & quoted form of middleFile
do shell script "sed 's/^$/\\ <br \\/>/g' " & quoted form of middleFile & " >" & quoted form of outFile
它有效,但它是多余的(而且很愚蠢?)。谁能让它更简洁?是否可以只涉及一个文本文件而不是三个(即 /Users/myname/Desktop/URLlist.txt 中的原始内容被最终结果覆盖)?
非常感谢您提前。