Curl用のURLコピーからヘッダー分離
#!/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 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
############################
###CURLとしてコピーしているか?
############################
if (ocidPasteboardStrings as text) starts with "curl" then
set strCurlURL to ocidPasteboardStrings as text
else
return "CURLとしてコピーしてください"
end if
set strCurlURL to (refMe's NSString's stringWithString:strCurlURL)
####呼び出し
set ocidReturnArray to doSeparateURL(strCurlURL) as list
####結果
set strCopyURL to (item 1 of ocidReturnArray)'s absoluteString() as text
set ocidCopyURL to (item 2 of ocidReturnArray)
set strQuieryText to (item 3 of ocidReturnArray) as text
set strHeaderText to (item 4 of ocidReturnArray) as text
#################################
##### CURL用ヘッダー分離
#################################
to doSeparateURL(argTextCurlURL)
try
set refClass to class of argTextCurlURL as text
if refClass is "text" then
set ocidCurlURLstr to (refMe's NSString's stringWithString:argTextCurlURL)
else
error "テキスト形式以外" number -10000
return "テキスト形式以外"
end if
on error
set ocidCurlURLstr to argTextCurlURL
end try
####テキスト確定している
set ocidTextCurlURL to refMe's NSMutableString's alloc()'s initWithCapacity:0
ocidTextCurlURL's appendString:ocidCurlURLstr
###戻り値用のリスト
set ocidDoSeparateURLArrayM to refMe's NSMutableArray's alloc()'s initWithCapacity:0
###改行を取る
set ocidCurlURLLength to ocidTextCurlURL's |length|()
set ocidCurlURLRange to {location:0, |length|:ocidCurlURLLength}
ocidTextCurlURL's replaceOccurrencesOfString:("\n") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidCurlURLRange
set ocidCurlURLLength to ocidTextCurlURL's |length|()
set ocidCurlURLRange to {location:0, |length|:ocidCurlURLLength}
ocidTextCurlURL's replaceOccurrencesOfString:("\r") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidCurlURLRange
###『'』でリスト化して2番目がURL
set ocidDelimiters to (refMe's NSCharacterSet)'s characterSetWithCharactersInString:"'"
set ocidCurlURLArray to ocidTextCurlURL's componentsSeparatedByCharactersInSet:ocidDelimiters
# log ocidCurlURLArray as list
###URL確定(クエリー入り)
set ocidURLString to ocidCurlURLArray's objectAtIndex:1
set ocidURL to refMe's NSURL's URLWithString:ocidURLString
# log ocidURL's absoluteString() as text
ocidDoSeparateURLArrayM's addObject:ocidURL
###URL部分(クエリー無し)
set ocidURLComponents to (refMe's NSURLComponents)'s componentsWithURL:ocidURL resolvingAgainstBaseURL:true
ocidURLComponents's setQueryItems:(missing value)
set ocidBaseURL to ocidURLComponents's |URL|
# log ocidBaseURL's absoluteString() as text
ocidDoSeparateURLArrayM's addObject:ocidBaseURL
###クエリー部分
set ocidQueryName to ocidURL's query()
# log ocidQueryName as text
if ocidQueryName is missing value then
ocidDoSeparateURLArrayM's addObject:""
else
ocidDoSeparateURLArrayM's addObject:ocidQueryName
end if
###ヘッダー部処理
###-1はゼロベースなので
set numCntURLArray to (ocidCurlURLArray's |count|()) - 1 as integer
set ocidIndexSet to refMe's NSMutableIndexSet's alloc()'s init()
###最初がcurlで2つ目がURLだから2コ目から=0ベースなので
set ocidRange to refMe's NSMakeRange(2, (numCntURLArray - 2))
set ocidNewIndex to refMe's NSIndexSet's indexSetWithIndexesInRange:ocidRange
###必用なインデックスセットで取り出して
set ocidHeaderArray to (ocidCurlURLArray's objectsAtIndexes:(ocidNewIndex))
###テキストにして
set ocidHeader to ocidHeaderArray's componentsJoinedByString:"'"
###最後のシングルクオトが取れちゃうから追加
ocidHeader's appendString:"'"
ocidDoSeparateURLArrayM's addObject:ocidHeader
###値を戻す
return ocidDoSeparateURLArrayM
end doSeparateURL
| 固定リンク
「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)