让许多人感到沮丧的一件事是当您想将多个变量传递给一个动作时遇到的问题。有一些方法可以解决它,例如保存到外部脚本。
但在这种情况下,一个简单的 Applescript 与@adayzdone 给你的脚本混合在一起,你会得到我认为你想要的东西。
您只需要将 URL 列表传递给此“运行 Applescript”
on run {input, parameters}
set docPath to POSIX path of (path to documents folder)
repeat with i from 1 to count of items of input
set this_item to item i of input
set thePage to (do shell script "curl " & quoted form of this_item)
set theTitle to docPath & "/" & (do shell script "echo " & quoted form of thePage & " | grep -o \\<title\\>.*\\</title\\> | sed -E 's/<\\/?title>//g'")
set t_text to (do shell script "echo " & quoted form of thePage & "|textutil -format html -convert txt -stdin -output \"" & theTitle & ".txt\"")
end repeat
end run
** 将文本传递到下一个操作的更新。**
这将传递来自所有 URL 的文本内容列表。
它仍然会执行上述操作,但现在会将所有 URL 中的文本内容列表传递给下一个操作。
我已经用“文本到语音”对其进行了测试,它可以读取多个文本内容。
on run {input, parameters}
set docPath to POSIX path of (path to documents folder)
set bigList to {}
repeat with i from 1 to count of items of input
set this_item to item i of input
set thePage to (do shell script "curl " & quoted form of this_item)
set theTitle to docPath & "/" & (do shell script "echo " & quoted form of thePage & " | grep -o \\<title\\>.*\\</title\\> | sed -E 's/<\\/?title>//g'")
set t_text to (do shell script "echo " & quoted form of thePage & "|textutil -format html -convert txt -stdin -output \"" & theTitle & ".txt\"")
set t_text_for_action to (do shell script "echo " & quoted form of thePage & "|textutil -format html -convert txt -stdin -stdout")
copy t_text_for_action to end of bigList
end repeat
return bigList --> text list can now be passed to the next action
end run
如果您想测试:我可以建议一个在山雀上有少量文字的页面,例如:http ://www.javascripter.net/
更新 2 - 使用 unix 命令“say”将文本保存到音频文件。
好的,这里有几件事。
1,出于同样的原因,我在之前的编码中将所有内容都保存在一个脚本中。我在这里做了同样的事情。即,将文本对象和标题一起传递给下一个动作即使不是不可能也很痛苦。
2,该脚本使用unix命令和它的输出选项将文本保存为aiff文件。它还按标题命名文件。
3,我遇到了一个问题,不是保存文件而是开始朗读文本。???事实证明,我正在测试的 URL ( http://www.javascripter.net ) 有一个大写的标题标签。所以脚本的@adayzdone grep和sed部分正在返回 "" 。这抛出了说命令。
我通过在grep命令中使用-i(忽略大小写)选项并使用“|”来解决此问题 ( or) sed中的选项并添加表达式的大写版本。
4、返回的Title中还有其他字符,由于没有添加扩展名,会导致文件被系统保存为可识别文件的问题。
这由一个简单的处理程序修复,该处理程序返回带有允许字符的标题文本。
6、
有用。
on run {input, parameters}
set docPath to POSIX path of (path to documents folder)
repeat with i from 1 to count of items of input
set this_item to item i of input
set thePage to (do shell script "curl -A \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.112 Safari/534.30\" " & quoted form of this_item)
set theTitle to replaceBadChars((do shell script "echo " & quoted form of thePage & " | grep -io \\<title\\>.*\\</title\\> | sed -E 's/<\\/?title>|<\\/?TITLE>//g'"))
set t_text_for_action to (do shell script "echo " & quoted form of thePage & "|textutil -format html -convert txt -stdin -stdout")
do shell script "cd " & quoted form of docPath & " ;say -o \"" & theTitle & "\" , " & quoted form of t_text_for_action
end repeat
end run
on replaceBadChars(TEXT_)
log TEXT_
set OkChars to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "_", space}
set TEXT_ to characters of TEXT_
repeat with i from 1 to count of items in TEXT_
set this_char to item i of TEXT_
if this_char is not in OkChars then
set item i of TEXT_ to "_"
else
end if
end repeat
set TEXT_ to TEXT_ as string
do shell script " echo " & quoted form of TEXT_
end replaceBadChars