連番ファイル名の連続ダウンロード
#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()
###ヘッダー固定用
set strHeaderText to " -X 'GET' \n-H 'Pragma: no-cache' -H 'Cache-Control: no-cache' \n-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Safari/605.1.15' \n-H 'Connection: keep-alive'" as text
################################
######ペーストボードを取得
################################
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
set ocidPasteboardArray to ocidPasteboard's readObjectsForClasses:({refMe's NSString}) options:(missing value)
set ocidPasteboardStrings to (ocidPasteboardArray's objectAtIndex:0) as text
###クリップボードの中身をダイアログのデフォルトに
set strDefaultAnswer to ocidPasteboardStrings as text
################################
######ダイアログ
################################
set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/BookmarkIcon.icns" as alias
try
set recordResponse to (display dialog "詳しく" with title "短め" default answer strDefaultAnswer buttons {"OK", "キャンセル"} default button "OK" cancel button "キャンセル" with icon aliasIconPath giving up after 20 without hidden answer)
on error
log "エラーしました"
return "エラーしました"
error number -128
end try
if true is equal to (gave up of recordResponse) then
return "時間切れですやりなおしてください"
error number -128
end if
if "OK" is equal to (button returned of recordResponse) then
set strResponse to (text returned of recordResponse) as text
else
log "エラーしました"
return "エラーしました"
error number -128
end if
####################################################
####ヘッダーをストリングにして
set ocidHeaderTextstr to (refMe's NSString's stringWithString:strHeaderText)
###可変テキストに
set ocidHeaderText to refMe's NSMutableString's alloc()'s initWithCapacity:0
ocidHeaderText's appendString:ocidHeaderTextstr
###改行除去
set ocidCurlURLLength to ocidHeaderText's |length|()
set ocidCurlURLRange to {location:0, |length|:ocidCurlURLLength}
ocidHeaderText's replaceOccurrencesOfString:("\n") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidCurlURLRange
set ocidCurlURLLength to ocidHeaderText's |length|()
set ocidCurlURLRange to {location:0, |length|:ocidCurlURLLength}
ocidHeaderText's replaceOccurrencesOfString:("\r") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidCurlURLRange
set strHeaderText to ocidHeaderText as text
####################################################
####URLの処理
set ocidURLstr to (refMe's NSString's stringWithString:strResponse)
set ocidURL to refMe's NSURL's URLWithString:ocidURLstr
set ocidBseURL to ocidURL's URLByDeletingLastPathComponent()
set ocidHostName to ocidURL's |host|()
set ocidExtensionName to ocidURL's pathExtension()
set ocidFileName to ocidBseURL's lastPathComponent()
set ocidBaseFileName to ocidFileName's stringByDeletingPathExtension()
####ユーザーダウンロードフォルダ
set ocidUserDownloadsPathArray to (appFileManager's URLsForDirectory:(refMe's NSDownloadsDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidUserDownloadsPathURL to ocidUserDownloadsPathArray's objectAtIndex:0
set ocidSaveDirPathURL to ocidUserDownloadsPathURL's URLByAppendingPathComponent:ocidHostName
###フォルダを作る
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
set numCntNo to 1 as integer
repeat 50 times
#####カウンターを追加
set ocidDownLoadURL to ocidBseURL's URLByAppendingPathComponent:(numCntNo as text)
set ocidDownLoadURL to ocidDownLoadURL's URLByAppendingPathExtension:ocidExtensionName
set strDownLoadURL to ocidDownLoadURL's absoluteString() as text
###ファイル名確定
set ocidDownLoadFileName to ocidDownLoadURL's lastPathComponent()
set ocidDownLoadFileURL to ocidSaveDirPathURL's URLByAppendingPathComponent:ocidDownLoadFileName
set strDownLoadFileURL to ocidDownLoadFileURL's |path|() as text
###コマンド整形
set strCommandText to "/usr/bin/curl '" & strDownLoadURL & "' -o '" & strDownLoadFileURL & "' " & strHeaderText & "" as text
###実行
do shell script strCommandText
####カウントアップ
set numCntNo to numCntNo + 1 as integer
end repeat
| 固定リンク
「CURL」カテゴリの記事
- [curl]rapid-cloudビデオ・ダウンロードヘルパー(簡易式)(2025.01.16)
- CURLでのURLチェック (404以外の応答があるURLのみ収集)(2024.12.03)
- [CURL]ヘッダー付きダウンロード(2024.11.23)
- 【CURL】基本的な事項(2023.10.24)
- [CURL]リダイレクト先URL(2023.10.19)