我有这个脚本应该逐行转到文本文件,如果每行都有一个URL,它应该在safari的单独选项卡中打开它 没有URL有效性检查的部分可以正常工作,但是当我使用CURL时它没有用,有什么帮助吗?
set myDelay to 0.2
set errorLog to {}
set urlText to read POSIX file "/USERS/KAMEL/transfer.txt" as «class utf8»
set urlList to paragraphs of urlText
repeat with aUrl in urlList
set aUrl to contents of aUrl
if aUrl ≠ "" then
try
do shell script "curl " & aUrl
tell application "Safari" to open location aUrl
-- open location aUrl
delay myDelay
on error
set end of errorLog to aUrl
exit repeat
end try
end if
end repeat
答案 0 :(得分:0)
Safari有专门的API来创建新标签。
试试这个,它使用curl返回HTTP状态代码
set urlText to read file ((path to home folder as text) & "transfer.txt") as «class utf8»
set urlList to paragraphs of urlText
set errorLog to {}
tell application "Safari" to if (count documents) is 0 then make new document
repeat with aUrl in urlList
set theScript to "curl -o /dev/null -s -I -w '%{http_code}' " & aUrl
try
set theStatus to (do shell script theScript) as integer
if theStatus < 400 then
tell application "Safari"
tell window 1 to make new tab with properties {URL:aUrl}
end tell
end if
on error e
set end of errorLog to (e & space & aUrl)
end try
end repeat