CURLでのURLチェック (404以外の応答があるURLのみ収集)
AppleScript サンプルコード
行番号 | ソース |
---|---|
001 | #!/usr/bin/env osascript |
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
003 | # URLチェッカー |
004 | # 応答が404以外の場合のURLのみ戻す |
005 | #com.cocolog-nifty.quicktimer.icefloe |
006 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
007 | use AppleScript version "2.8" |
008 | use framework "Foundation" |
009 | use framework "AppKit" |
010 | use scripting additions |
011 | property refMe : a reference to current application |
012 | |
013 | |
014 | set aliasPathToMe to (path to me) as alias |
015 | set strPathToMe to (POSIX path of aliasPathToMe) as text |
016 | set ocidPathToMeStr to refMe's NSString's stringWithString:(strPathToMe) |
017 | set ocidPathToMe to ocidPathToMeStr's stringByStandardizingPath() |
018 | set ocidPathToMeURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidPathToMe) isDirectory:(false) |
019 | set ocidContainerDirPathURL to ocidPathToMeURL's URLByDeletingLastPathComponent() |
020 | set ocidFilePathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:("data/URL_LIST.txt") isDirectory:(false) |
021 | # |
022 | set listResponse to refMe's NSString's alloc()'s initWithContentsOfURL:(ocidFilePathURL) encoding:(refMe's NSUTF8StringEncoding) |error| :(reference) |
023 | set ocidReadString to (item 1 of listResponse) |
024 | # |
025 | set ocidURLStringArray to ocidReadString's componentsSeparatedByString:("\n") |
026 | # |
027 | set ocidOutPuttring to refMe's NSMutableString's alloc()'s initWithCapacity:(0) |
028 | # |
029 | repeat with itemURLstring in ocidURLStringArray |
030 | if itemURLstring is not "" then |
031 | set strCommandText to ("/usr/bin/curl -I \"" & itemURLstring & "\"") as text |
032 | set strResponset to (do shell script strCommandText) as text |
033 | if strResponset contains "404" then |
034 | #見つからなかった |
035 | else |
036 | log itemURLstring as text |
037 | (ocidOutPuttring's appendString:(itemURLstring)) |
038 | (ocidOutPuttring's appendString:("\n")) |
039 | end if |
040 | end if |
041 | end repeat |
042 | |
043 | ############################## |
044 | #####ダイアログ |
045 | ############################## |
046 | ##前面に出す |
047 | set strName to (name of current application) as text |
048 | if strName is "osascript" then |
049 | tell application "Finder" to activate |
050 | else |
051 | tell current application to activate |
052 | end if |
053 | ###アイコンパス |
054 | set aliasIconPath to POSIX file "/System/Applications/Calculator.app/Contents/Resources/AppIcon.icns" as alias |
055 | set strMes to ("戻り値です") as text |
056 | set recordResult to (display dialog strMes with title "選んでください" default answer (ocidOutPuttring as text) buttons {"クリップボードにコピー", "キャンセル"} default button "クリップボードにコピー" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer) |
057 | |
058 | |
059 | ###クリップボードコピー |
060 | if button returned of recordResult is "クリップボードにコピー" then |
061 | set strText to (text returned of recordResult) as text |
062 | try |
063 | ####ペーストボード宣言 |
064 | set appPasteboard to refMe's NSPasteboard's generalPasteboard() |
065 | set ocidText to (refMe's NSString's stringWithString:(strIP)) |
066 | appPasteboard's clearContents() |
067 | appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString) |
068 | on error |
069 | tell application "Finder" |
070 | set the clipboard to strText as text |
071 | end tell |
072 | end try |
073 | end if |
074 | |
075 | |
076 | |
077 | |
078 | |
079 | |
080 | return ocidOutPuttring as text |
AppleScriptで生成しました |
| 固定リンク