2016-07-13 7 views
0

私はこのスクリプトを1行ずつテキストファイルに送り、各行にURLがあれば、Safariの別のタブで開きます。 URLの有効性のない部分チェックは機能しますが、私はCURLを使用していません。AppleScriptでURLの有効性が確認されていない

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

Safariには、新しいタブを作成する専用のAPIがあります。

それは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 
を返すためにカール使用して、これを試してみてください
関連する問題