« [CURL]リダイレクト先のファイル名取得 | トップページ | [CURL]リダイレクト先URL »

[CURL]リダイレクト先のファイルサイズ


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
----+----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


###########【1】リダイレクト先のURLを求める
(*
-I --head ヘッダーのみ
-s サイレント 詳細ログを出さない
-L リダイレクト先の応答を取得
-o /dev/null  出力は捨てる
--write-out -w フォーマットの基づいた結果を表示
*)
set strURL to "https://go.microsoft.com/fwlink/?linkid=2093504" as text
###コマンド整形
set strCommandText to ("/usr/bin/curl --head -s -L -o /dev/null -w '%{url_effective}' \"" & strURL & "\"") as text
##実行
set strRedirectURL to (do shell script strCommandText) as text
###########【2】リダイレクト先のファイル名を求める
set strCommandText to ("/usr/bin/basename \"" & strRedirectURL & "\"") as text
set strFileName to (do shell script strCommandText) as text
########【3】リダイレクト先のファイルのファイルサイズを求める
set strCommandText to ("/usr/bin/curl --head -L \"" & strRedirectURL & "\" | grep \"Content-Length\" | /usr/bin/sed 's/[^0-9]*//g'") as text
##実行
set strFileSize to (do shell script strCommandText) as text
##戻り値
log strFileSize
return strFileSize



|

« [CURL]リダイレクト先のファイル名取得 | トップページ | [CURL]リダイレクト先URL »

CURL」カテゴリの記事