AppleScript NSURL

日本語ドメイン名のエンコード値を取得する


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#
005#
006#com.cocolog-nifty.quicktimer.icefloe
007----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
008use AppleScript version "2.8"
009use framework "Foundation"
010use framework "AppKit"
011use scripting additions
012
013property refMe : a reference to current application
014
015################################
016##デフォルトクリップボードからテキスト取得
017################################
018set appPasteboard to refMe's NSPasteboard's generalPasteboard()
019set ocidTypeArray to appPasteboard's types()
020set boolContain to ocidTypeArray's containsObject:("public.utf8-plain-text")
021if boolContain = true then
022  try
023    set ocidPasteboardArray to appPasteboard's readObjectsForClasses:({refMe's NSString}) options:(missing value)
024    set ocidPasteboardStrings to ocidPasteboardArray's firstObject()
025  on error
026    set ocidStringData to appPasteboard's stringForType:("public.utf8-plain-text")
027    set ocidPasteboardStrings to (refMe's NSString's stringWithString:(ocidStringData))
028  end try
029else
030  set ocidPasteboardStrings to (refMe's NSString's stringWithString:(""))
031end if
032set strDefaultAnswer to ocidPasteboardStrings as text
033
034################################
035######ダイアログ
036################################
037#####ダイアログを前面に
038tell current application
039  set strName to name as text
040end tell
041####スクリプトメニューから実行したら
042if strName is "osascript" then
043  tell application "Finder" to activate
044else
045  tell current application to activate
046end if
047set aliasIconPath to (POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/BookmarkIcon.icns") as alias
048try
049  set strMes to ("日本語ドメイン名をhttp://日本語.jp/等URL形式でペースト") as text
050  
051  set recordResponse to (display dialog strMes with title "入力してください" default answer strDefaultAnswer buttons {"OK", "キャンセル"} default button "OK" cancel button "キャンセル" with icon aliasIconPath giving up after 20 without hidden answer)
052on error
053  log "エラーしました"
054  return "エラーしました"
055end try
056if true is equal to (gave up of recordResponse) then
057  return "時間切れですやりなおしてください"
058end if
059if "OK" is equal to (button returned of recordResponse) then
060  set strResponse to (text returned of recordResponse) as text
061else
062  log "キャンセルしました"
063  return "キャンセルしました"
064end if
065
066##############################
067###URLと通常テキストの処理を分岐する
068##URLの場合
069set ocidTextString to refMe's NSString's stringWithString:(strResponse)
070if strResponse starts with "http" then
071  #webURL
072  set ocidURL to refMe's NSURL's alloc()'s initWithString:(ocidTextString)
073  set strTextToEncoded to ocidURL's absoluteString() as text
074else if strResponse starts with "file:/" then
075  return "エラー"
076else
077  #通常文字列
078  return "エラー"
079end if
080
081
082################################
083######ダイアログ
084################################
085#####ダイアログを前面に
086tell current application
087  set strName to name as text
088end tell
089####スクリプトメニューから実行したら
090if strName is "osascript" then
091  tell application "Finder" to activate
092else
093  tell current application to activate
094end if
095set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns"
096set strMes to ("戻り値です\r" & strTextToEncoded) as text
097
098set recordResult to (display dialog strMes with title "エンコード結果" default answer strTextToEncoded buttons {"クリップボードにコピー", "キャンセル", "OK"} default button "OK" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer)
099
100if button returned of recordResult is "クリップボードにコピー" then
101  try
102    set strText to text returned of recordResult as text
103    ####ペーストボード宣言
104    set appPasteboard to refMe's NSPasteboard's generalPasteboard()
105    set ocidText to (refMe's NSString's stringWithString:(strText))
106    appPasteboard's clearContents()
107    appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
108  on error
109    tell application "Finder"
110      set the clipboard to strText as text
111    end tell
112  end try
113end if
114
115return
AppleScriptで生成しました

|

[x-apple-findertag]タグのNSURL


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

#!/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 framework "AppKit"
use scripting additions

property refMe : a reference to current application

set itemTagName to "レッド"
###コンポーネント初期化
set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
###スキーム を追加
ocidURLComponents's setScheme:("x-apple-findertag")
###パスを追加(setHostじゃないよ)
ocidURLComponents's setPath:(itemTagName)
set ocidTagURL to ocidURLComponents's |URL|
log ocidTagURL's absoluteString() as text
-->(*x-apple-findertag:%E3%83%AC%E3%83%83%E3%83%89*)

|

[NSURL] eMailのNSURL


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

#!/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.6"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

###コンポーネント初期化
set ocidComponents to refMe's NSURLComponents's alloc()'s init()
###スキーム mailtoを追加
ocidComponents's setScheme:("mailto")
###パスを追加(setHostじゃないよ)
ocidComponents's setPath:("foo@mail.hoge.com")
###URLに
set ocidEmailURL to ocidComponents's |URL|
log ocidEmailURL's absoluteString() as text
-->(*mailto:foo@mail.hoge.com*)


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

#!/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.6"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

###コンポーネント初期化
set ocidEmailComponents to refMe's NSURLComponents's alloc()'s init()
###スキーム mailtoを追加
ocidEmailComponents's setScheme:("mailto" )
###パスを追加(setHostじゃないよ)
ocidEmailComponents's setPath:("foo@hoge.com" )
###クエリー追加
set ocidQueryItemArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
set ocidQueryItem to refMe's NSURLQueryItem's alloc()'s initWithName:("subject") value:("【件名】よろしくお願いします")
ocidQueryItemArray's addObject:ocidQueryItem
set ocidQueryItem to refMe's NSURLQueryItem's alloc()'s initWithName:("body") value:("お世話になります")
ocidQueryItemArray's addObject:ocidQueryItem
set ocidQueryItem to refMe's NSURLQueryItem's alloc()'s initWithName:("cc") value:("cc@mail.foo.hoge.com")
ocidQueryItemArray's addObject:ocidQueryItem
set ocidQueryItem to refMe's NSURLQueryItem's alloc()'s initWithName:("bcc") value:("bcc@mail.foo.hoge.com")
ocidQueryItemArray's addObject:ocidQueryItem
ocidEmailComponents's setQueryItems:(ocidQueryItemArray)
###URLに
set ocidEmailURL to ocidEmailComponents's |URL|
log ocidEmailURL's absoluteString() as text


|

連番URL


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003## com.cocolog-nifty.quicktimer.icefloe
004----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
005##自分環境がos12なので2.8にしているだけです
006use AppleScript version "2.8"
007use framework "Foundation"
008use scripting additions
009
010property refMe : a reference to current application
011
012set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
013ocidURLComponents's setScheme:"https"
014ocidURLComponents's setHost:"foo.hoge.com"
015ocidURLComponents's setPath:"/some/path/file.html"
016set ocidURLStrings to ocidURLComponents's |URL|'s absoluteString()
017set ocidURL to refMe's NSURL's alloc()'s initWithString:(ocidURLStrings)
018
019log ocidURL's absoluteString() as text
020-->(*https://foo.hoge.com/some/path/file.html*)
021
022log ocidURL's |scheme| as text
023log ocidURL's |host| as text
024log ocidURL's |path| as text
025set ocidExtension to ocidURL's pathExtension
026
027set ocidFileName to ocidURL's lastPathComponent
028set ocidBaseFileName to ocidFileName's stringByDeletingPathExtension()
029set ocidBaseURL to ocidURL's URLByDeletingLastPathComponent()
030
031set numFileCnt to 1 as integer
032repeat 20 times
033  ###連番ゼロ付与
034  set strZeroPad to ("000" & (numFileCnt as text)) as text
035  set strZeroPad to (text -3 through -1 of strZeroPad) as text
036  ###ファイル名に連番つける
037  set ocidNewFileName to ocidBaseFileName's stringByAppendingString:(strZeroPad)
038  ###拡張子つけて
039  set ocidNewFileName to ocidNewFileName's stringByAppendingPathExtension:(ocidExtension)
040  ###新しいURLに
041  set ocidNewURL to ocidBaseURL's URLByAppendingPathComponent:ocidNewFileName
042  log ocidNewURL's absoluteString() as text
043  set numFileCnt to numFileCnt + 1 as integer
044end repeat
AppleScriptで生成しました

|

[NSURL]URLとヘッダーの分解(CURLとしてコピー)

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos13なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application
property refNSString : a reference to refMe's NSString
property refNSURL : a reference to refMe's NSURL
property refNSData : a reference to refMe's NSData
property refNSMutableString : a reference to refMe's NSMutableString
property refNSMutableArray : a reference to refMe's NSMutableArray


property refNSPasteboard : a reference to refMe's NSPasteboard
set ocidPasteboard to refNSPasteboard's generalPasteboard()

###クリックボードの中のURLを取得
set ocidPasteboardTypeString to ocidPasteboard's stringForType:(refMe's NSPasteboardTypeString)

##可変テキスト形式で格納
set ocidCurlURL to refNSMutableString's alloc()'s initWithCapacity:0
ocidCurlURL's setString:ocidPasteboardTypeString

if (ocidCurlURL as text) starts with "curl" then
log "処理開始"
set ocidDoSeparateURLArrayM to doSeparateURL(ocidCurlURL)
else
return "CURLとしてコピーしてください"
end if

log (item 1 of ocidDoSeparateURLArrayM)'s absoluteString() as text
log (item 2 of ocidDoSeparateURLArrayM)'s absoluteString() as text
log item 3 of ocidDoSeparateURLArrayM as text
log item 4 of ocidDoSeparateURLArrayM as text




to doSeparateURL(ocidCurlURL)
###戻り値用のリスト
set ocidDoSeparateURLArrayM to refNSMutableArray's alloc()'s initWithCapacity:0

###改行を取る
set ocidCurlURLLength to ocidCurlURL's |length|()
set ocidCurlURLRange to {location:0, |length|:ocidCurlURLLength}
ocidCurlURL's replaceOccurrencesOfString:("\n") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidCurlURLRange
###'』でリスト化して2番目がURL
set ocidDelimiters to (refMe's NSCharacterSet)'s characterSetWithCharactersInString:"'"
set ocidCurlURLArray to ocidCurlURL's componentsSeparatedByCharactersInSet:ocidDelimiters

###URL確定(クエリー入り)
set ocidURLString to ocidCurlURLArray's objectAtIndex:1
set ocidURL to refNSURL'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
###ヘッダー部処理
set ocidDelimiters to (refMe's NSCharacterSet)'s characterSetWithCharactersInString:"\\"
set ocidHeaderArray to ocidCurlURL's componentsSeparatedByCharactersInSet:ocidDelimiters
set ocidHeaderArrayLength to ocidHeaderArray's |count|()
set ocidHeaderRange to refMe's NSMakeRange(1, (ocidHeaderArrayLength - 1))
set ocidSubbArray to ocidHeaderArray's subarrayWithRange:ocidHeaderRange
set ocidHeaderText to (ocidSubbArray's componentsJoinedByString:"")

log ocidHeaderText as text
ocidDoSeparateURLArrayM's addObject:ocidHeaderText
###値を戻す
return ocidDoSeparateURLArrayM

end doSeparateURL

|

[NSURL]URLとヘッダーの分解(CURLとしてコピー)

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos13なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application
property refNSString : a reference to refMe's NSString
property refNSURL : a reference to refMe's NSURL
property refNSData : a reference to refMe's NSData
property refNSMutableString : a reference to refMe's NSMutableString

property refNSPasteboard : a reference to refMe's NSPasteboard
set ocidPasteboard to refNSPasteboard's generalPasteboard()

###クリックボードの中のURLを取得
set ocidPasteboardTypeString to ocidPasteboard's stringForType:(refMe's NSPasteboardTypeString)

##可変テキスト形式で格納
set ocidCurlURL to refNSMutableString's alloc()'s initWithCapacity:0
ocidCurlURL's setString:ocidPasteboardTypeString

if (ocidCurlURL as text) starts with "curl" then
log "処理開始"
else
return "CURLとしてコピーしてください"
end if

###改行を取る
set ocidCurlURLLength to ocidCurlURL's |length|()
set ocidCurlURLRange to {location:0, |length|:ocidCurlURLLength}
ocidCurlURL's replaceOccurrencesOfString:("\n") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidCurlURLRange

###'』でリスト化して2番目がURL
set ocidDelimiters to (refMe's NSCharacterSet)'s characterSetWithCharactersInString:"'"
set ocidCurlURLArray to ocidCurlURL's componentsSeparatedByCharactersInSet:ocidDelimiters

###URL確定(クエリー入り)
set ocidURLString to ocidCurlURLArray's objectAtIndex:1
set ocidURL to refNSURL's URLWithString:ocidURLString
log ocidURL's absoluteString() as text

###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

###クエリー部分
set ocidQueryName to ocidURL's query()
log ocidQueryName as text

###ヘッダー部
set ocidDelimiters to (refMe's NSCharacterSet)'s characterSetWithCharactersInString:"\\"
set ocidHeaderArray to ocidCurlURL's componentsSeparatedByCharactersInSet:ocidDelimiters
set ocidHeaderArrayLength to ocidHeaderArray's |count|()
set ocidHeaderRange to refMe's NSMakeRange(1, (ocidHeaderArrayLength - 1))
set ocidSubbArray to ocidHeaderArray's subarrayWithRange:ocidHeaderRange
set ocidHeaderText to (ocidSubbArray's componentsJoinedByString:"")

log ocidHeaderText as text
return

























to doGetErrorData(ocidNSErrorData)
#####個別のエラー情報
log "エラーコード:" & ocidNSErrorData's code() as text
log "エラードメイン:" & ocidNSErrorData's domain() as text
log "Description:" & ocidNSErrorData's localizedDescription() as text
log "FailureReason:" & ocidNSErrorData's localizedFailureReason() as text
log ocidNSErrorData's localizedRecoverySuggestion() as text
log ocidNSErrorData's localizedRecoveryOptions() as text
log ocidNSErrorData's recoveryAttempter() as text
log ocidNSErrorData's helpAnchor() as text
set ocidNSErrorUserInfo to ocidNSErrorData's userInfo()
set ocidAllValues to ocidNSErrorUserInfo's allValues() as list
set ocidAllKeys to ocidNSErrorUserInfo's allKeys() as list
repeat with ocidKeys in ocidAllKeys
if (ocidKeys as text) is "NSUnderlyingError" then
log (ocidNSErrorUserInfo's valueForKey:ocidKeys)'s localizedDescription() as text
log (ocidNSErrorUserInfo's valueForKey:ocidKeys)'s localizedFailureReason() as text
log (ocidNSErrorUserInfo's valueForKey:ocidKeys)'s localizedRecoverySuggestion() as text
log (ocidNSErrorUserInfo's valueForKey:ocidKeys)'s localizedRecoveryOptions() as text
log (ocidNSErrorUserInfo's valueForKey:ocidKeys)'s recoveryAttempter() as text
log (ocidNSErrorUserInfo's valueForKey:ocidKeys)'s helpAnchor() as text
else
####それ以外の値はそのままテキストで読める
log (ocidKeys as text) & ": " & (ocidNSErrorUserInfo's valueForKey:ocidKeys) as text
end if
end repeat

end doGetErrorData

|

[NSURL] initWithString URLの組み立て

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

######ログ表示
doLogView()

property objMe : a reference to current application
property objNSString : a reference to objMe's NSString
property objNSMutableString : a reference to objMe's NSMutableString
property objNSURL : a reference to objMe's NSURL
property objNSURLComponents : a reference to objMe's NSURLComponents
property objNSNotFound : a reference to 9.22337203685477E+18 + 5807


###空のテキスト
set ocidURLstring to objNSString's stringWithString:""
log ocidURLstring as text
log className() of ocidURLstring as text

###空のNSURL
set ocidNSURLinit to objNSURL's alloc()'s initWithString:ocidURLstring
log ocidNSURLinit's absoluteString() as text
log className() of ocidNSURLinit as text

####NSURLComponentsも初期化
set ocidNewURLComponents to objNSURLComponents's alloc()'s init()
log ocidNewURLComponents as list
log className() of ocidNewURLComponents as text


###スキーム追加
ocidNewURLComponents's setScheme:"https"
log ocidNewURLComponents's |scheme| as text
log className() of ocidNewURLComponents as text

####ホスト名追加
ocidNewURLComponents's setHost:"server1.www.aaa.co.jp"
log ocidNewURLComponents's |host| as text
log className() of ocidNewURLComponents as text

####ポート番号追加-->ここだけ数値
ocidNewURLComponents's setPort:8080
log ocidNewURLComponents's |port| as text
log className() of ocidNewURLComponents as text

####パス追加-->拡張子の追加はできない
ocidNewURLComponents's setPath:"/dir1/dir2/dir3/file.exe"
log ocidNewURLComponents's |path| as text
log className() of ocidNewURLComponents as text

####サーバー認証ユーザー名
ocidNewURLComponents's setUser:"MyName"
log ocidNewURLComponents's user as text
log className() of ocidNewURLComponents as text

####サーバー認証パスワード
ocidNewURLComponents's setPassword:"1234"
log ocidNewURLComponents's |password| as text
log className() of ocidNewURLComponents as text

####クエリー追加
ocidNewURLComponents's setQuery:"AAA=BBB&CCCC=DDD"
log ocidNewURLComponents's query as text
log className() of ocidNewURLComponents as text

####フラグメント-->アンカー追加
ocidNewURLComponents's setFragment:"Anchor"
log ocidNewURLComponents's fragment as text
log className() of ocidNewURLComponents as text

###ここまでのURLを表示
set strNewURL to ocidNewURLComponents's |URL|'s absoluteString()
log strNewURL as text
log className() of strNewURL as text



############
#NSURLQueryItemを使っての追加

####クエリーの内容を定義
set ocidURLQueryItemA to objMe's NSURLQueryItem's queryItemWithName:"AAA" value:"BBB"
log ocidURLQueryItemA's query as record
log className() of ocidURLQueryItemA as text

####クエリーの内容を定義
set ocidURLQueryItemB to objMe's NSURLQueryItem's queryItemWithName:"CCC" value:"DDD"
log ocidURLQueryItemB's query as record
log className() of ocidURLQueryItemB as text

###クエリーを追加
ocidNewURLComponents's setQueryItems:{ocidURLQueryItemA, ocidURLQueryItemB}
log ocidNewURLComponents's query as text
log className() of ocidNewURLComponents as text

set strNewURL to ocidNewURLComponents's |URL|'s absoluteString()
log strNewURL as text
log className() of strNewURL as text








#########################ログ表示
to doLogView()

tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
end if
end repeat

end doLogView
#########################

|

[NSURL]基本的な処理

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

######ログ表示
doLogView()

property objMe : a reference to current application
property objNSString : a reference to objMe's NSString
property objNSURL : a reference to objMe's NSURL


set strURL to "https://aaaa.bbbb.cccc.co.jp/DDDD/EEEE/FFFFF.exe?GGGG=HHH&IIII=JJJJ"


####テキストをNSURL
set ocidURL to objNSURL's URLWithString:strURL
log ocidURL's absoluteString() as text
log className() of ocidURL as text
-->(*NSURL*)

####パスコンポーネント
set ocidPathComponent to ocidURL's pathComponents()
log ocidPathComponent as list
log className() of ocidPathComponent as text
-->((*/, DDDD, EEEE, FFFFF.exe*)
-->((*__NSArrayM*)

########
## スキーマ
set ocidSchemeName to ocidURL's |scheme|()
log ocidSchemeName as text
log className() of ocidSchemeName as text
-->(*https*)
-->((*__NSCFConstantString*)

########
###スキーマを抜いたURL
set ocidNSURLResourceSpecifier to ocidURL's resourceSpecifier()
log ocidNSURLResourceSpecifier as text
log className() of ocidNSURLResourceSpecifier as text
-->(*__NSCFString*)
-->(*//aaaa.bbbb.cccc.co.jp/DDDD/EEEE/FFFFF.exe?GGGG=HHH&IIII=JJJJ*)

########
## ホスト名
set ocidHostName to ocidURL's |host|()
log ocidHostName as text
log className() of ocidHostName as text
-->(*aaaa.bbbb.cccc.co.jp*)
-->(*__NSCFString*)

########
## パス
set ocidPath to ocidURL's |path|()
log ocidPath as text
log className() of ocidPath as text
-->(*/DDDD/EEEE/FFFFF.exe*)
-->(*__NSCFString*)

########
## 最後のコンポーネント
set ocidLastPathComponent to ocidURL's lastPathComponent()
log ocidLastPathComponent as text
log className() of ocidLastPathComponent as text
-->(*FFFFF.exe*)
-->(*NSPathStore2*)

########
## クエリー
set ocidQueryName to ocidURL's query()
log ocidQueryName as text
log className() of ocidQueryName as text
-->(*GGGG=HHH&IIII=JJJJ*)
-->(*__NSConcreteURLComponents*)



###拡張子削除
set ocidDeleteExtension to ocidURL's URLByDeletingPathExtension
log ocidDeleteExtension's absoluteString() as text
log className() of ocidDeleteExtension as text
-->(*https://aaaa.bbbb.cccc.co.jp/DDDD/EEEE/FFFFF?GGGG=HHH&IIII=JJJJ*)
-->(*NSURL*)

set ocidAppendingExtension to ocidDeleteExtension's URLByAppendingPathExtension:"php"
log ocidAppendingExtension's absoluteString() as text
log className() of ocidDeleteExtension as text
-->(*https://aaaa.bbbb.cccc.co.jp/DDDD/EEEE/FFFFF.php?GGGG=HHH&IIII=JJJJ*)
-->(*NSURL*)

###最後のURLコンポーネントを削除
set ocidDeleteLastPath to ocidURL's URLByDeletingLastPathComponent
log ocidDeleteLastPath's absoluteString() as text
log className() of ocidDeleteLastPath as text
-->(*https://aaaa.bbbb.cccc.co.jp/DDDD/EEEE/?GGGG=HHH&IIII=JJJJ*)
-->(*NSURL*)

###URLコンポーネントを追加
set ocidAppendingLastPath to ocidDeleteLastPath's URLByAppendingPathComponent:"FFFFF"
log ocidAppendingLastPath's absoluteString() as text
log className() of ocidDeleteLastPath as text
-->(*https://aaaa.bbbb.cccc.co.jp/DDDD/EEEE/FFFFF?GGGG=HHH&IIII=JJJJ*)
-->(*NSURL*)

###resourceSpecifier()
set ocidDeleteLastPath to ocidAppendingLastPath's resourceSpecifier()
log ocidDeleteLastPath as text
log className() of ocidDeleteLastPath as text



################################################
####コンポーネントに格納
set ocidURLComponents to objMe's NSURLComponents's componentsWithURL:ocidURL resolvingAgainstBaseURL:true
log className() of ocidURLComponents as text
-->(*__NSConcreteURLComponents*)

####クエリー部分を削除
ocidURLComponents's setQueryItems:(missing value)
set strBaseURL to ocidURLComponents's |URL|'s absoluteString() as text
log class of strBaseURL as text
log strBaseURL
-->(*text*)
-->(*https://aaaa.bbbb.cccc.co.jp/DDDD/EEEE/FFFFF.exe*)

####テキストになるのでNSURL
set ocidbaseURL to objNSURL's URLWithString:strBaseURL
log className() of ocidbaseURL as text
-->(*NSURL*)

####拡張子
set ocidExtensionName to ocidbaseURL's pathExtension()
log ocidExtensionName as text
log className() of ocidExtensionName as text
-->(*exe*)
-->(*NSPathStore2 =パスの一部分として格納されているnotテキスト*)




#########################ログ表示
to doLogView()

tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
end if
end repeat

end doLogView
#########################

|

[NSURL] pathExtension 拡張子の取得

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

######ログ表示
doLogView()

property objMe : a reference to current application
property objNSString : a reference to objMe's NSString
property objNSURL : a reference to objMe's NSURL


set strURL to "https://developer.apple.com/documentation/foundation/nsurl.exe?AAAA=BBBB"


set ocidURL to objNSURL's URLWithString:strURL
log className() of ocidURL as text

set ocidURLComponents to objMe's NSURLComponents's componentsWithURL:ocidURL resolvingAgainstBaseURL:true
log className() of ocidURLComponents as text
log ocidURLComponents's |URL|'s absoluteString() as text

ocidURLComponents's setQueryItems:(missing value)
log className() of ocidURLComponents as text


ocidURLComponents's |URL|'s absoluteString()
log className() of ocidURLComponents as text

set strBaseURL to ocidURLComponents's |URL|'s absoluteString() as text
log class of strBaseURL as text

set ocidBaseURL to objNSURL's URLWithString:strBaseURL
log className() of ocidBaseURL as text


log ocidBaseURL's pathExtension() as text

#########################ログ表示
to doLogView()

tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
end if
end repeat

end doLogView
#########################

|

[NSURLComponents]setQueryItems:(missing value) URLのクエリー部分を削除

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

######ログ表示
doLogView()

property objMe : a reference to current application
property objNSString : a reference to objMe's NSString
property objNSURL : a reference to objMe's NSURL


set strURL to "https://developer.apple.com/documentation/foundation/nsurl?AAAA=BBBB"


set ocidURL to objNSURL's URLWithString:strURL
log className() of ocidURL as text

set ocidURLComponents to objMe's NSURLComponents's componentsWithURL:ocidURL resolvingAgainstBaseURL:true
log className() of ocidURLComponents as text
log ocidURLComponents's |URL|'s absoluteString() as text

ocidURLComponents's setQueryItems:(missing value)
log className() of ocidURLComponents as text


ocidURLComponents's |URL|'s absoluteString()
log className() of ocidURLComponents as text
log ocidURLComponents's |URL|'s absoluteString() as text



#########################ログ表示
to doLogView()

tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
end if
end repeat

end doLogView
#########################

|

より以前の記事一覧

その他のカテゴリー

Acrobat Acrobat 2020 Acrobat AddOn Acrobat Annotation Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat JS Acrobat Manifest Acrobat Menu Acrobat Open Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat python Acrobat Reader Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat Watermark Acrobat Windows Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin Support Admin System Information Admin Tools Admin Users Admin Volumes Adobe Adobe FDKO Adobe RemoteUpdateManager Apple AppleScript AppleScript Accessibility AppleScript AppKit AppleScript Applications AppleScript AppStore AppleScript Archive AppleScript Attributes AppleScript Audio AppleScript Automator AppleScript AVAsset AppleScript AVconvert AppleScript AVFoundation AppleScript AVURLAsset AppleScript BackUp AppleScript Barcode AppleScript Bash AppleScript Basic AppleScript Basic Path AppleScript Bluetooth AppleScript BOX AppleScript Browser AppleScript Calendar AppleScript CD/DVD AppleScript Choose AppleScript Chrome AppleScript CIImage AppleScript CloudStorage AppleScript Color AppleScript com.apple.LaunchServices.OpenWith AppleScript Console AppleScript Contacts AppleScript CotEditor AppleScript CURL AppleScript current application AppleScript Date&Time AppleScript delimiters AppleScript Desktop AppleScript Device AppleScript Diff AppleScript Disk AppleScript do shell script AppleScript Dock AppleScript DropBox AppleScript Droplet AppleScript eMail AppleScript Encode % AppleScript Encode Decode AppleScript Encode UTF8 AppleScript Error AppleScript EXIFData AppleScript ffmpeg AppleScript File AppleScript Finder AppleScript Firefox AppleScript Folder AppleScript Fonts AppleScript GIF AppleScript Guide AppleScript HTML AppleScript HTML Entity AppleScript Icon AppleScript Illustrator AppleScript Image Events AppleScript Image2PDF AppleScript ImageOptim AppleScript iWork AppleScript Javascript AppleScript Jedit AppleScript Json AppleScript Label AppleScript Leading Zero AppleScript List AppleScript locationd AppleScript LRC AppleScript LSSharedFileList AppleScript m3u8 AppleScript Mail AppleScript MakePDF AppleScript Map AppleScript Math AppleScript Messages AppleScript Microsoft AppleScript Microsoft Edge AppleScript Microsoft Excel AppleScript Mouse AppleScript Movie AppleScript Music AppleScript NetWork AppleScript Notes AppleScript NSArray AppleScript NSArray Sort AppleScript NSBitmapImageRep AppleScript NSBundle AppleScript NSCFBoolean AppleScript NSCharacterSet AppleScript NSColor AppleScript NSColorList AppleScript NSData AppleScript NSDictionary AppleScript NSError AppleScript NSEvent AppleScript NSFileAttributes AppleScript NSFileManager AppleScript NSFileManager enumeratorAtURL AppleScript NSFont AppleScript NSFontManager AppleScript NSGraphicsContext AppleScript NSImage AppleScript NSIndex AppleScript NSKeyedArchiver AppleScript NSKeyedUnarchiver AppleScript NSLocale AppleScript NSMutableArray AppleScript NSMutableDictionary AppleScript NSMutableString AppleScript NSNotFound AppleScript NSNumber AppleScript NSOpenPanel AppleScript NSPasteboard AppleScript NSpoint AppleScript NSPredicate AppleScript NSPrintOperation AppleScript NSRange AppleScript NSRect AppleScript NSRegularExpression AppleScript NSRunningApplication AppleScript NSScreen AppleScript NSSize AppleScript NSString AppleScript NSStringCompareOptions AppleScript NSTask AppleScript NSTimeZone AppleScript NSURL AppleScript NSURL File AppleScript NSURLBookmark AppleScript NSURLComponents AppleScript NSURLResourceKey AppleScript NSURLSession AppleScript NSUserDefaults AppleScript NSUUID AppleScript NSView AppleScript NSWorkspace AppleScript Numbers AppleScript OAuth AppleScript ObjC AppleScript OneDrive AppleScript Osax AppleScript PDF AppleScript PDFAnnotation AppleScript PDFAnnotationWidget AppleScript PDFContext AppleScript PDFDisplayBox AppleScript PDFDocumentPermissions AppleScript PDFImageRep AppleScript PDFKit AppleScript PDFnUP AppleScript PDFOutline AppleScript Photoshop AppleScript Pictures AppleScript PostScript AppleScript prefPane AppleScript Preview AppleScript Python AppleScript QR AppleScript QR Decode AppleScript QuickLook AppleScript QuickTime AppleScript record AppleScript Regular Expression AppleScript Reminders AppleScript ReName AppleScript Repeat AppleScript RTF AppleScript Safari AppleScript SaveFile AppleScript ScreenCapture AppleScript ScreenSaver AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript Sound AppleScript Spotlight AppleScript SRT AppleScript StandardAdditions AppleScript stringByApplyingTransform AppleScript Swift AppleScript System Events AppleScript System Events Plist AppleScript System Settings AppleScript TemporaryItems AppleScript Terminal AppleScript Text AppleScript Text CSV AppleScript Text MD AppleScript Text TSV AppleScript TextEdit AppleScript Translate AppleScript Trash AppleScript Twitter AppleScript UI AppleScript Unit Conversion AppleScript UTType AppleScript valueForKeyPath AppleScript Video AppleScript VisionKit AppleScript Visual Studio Code AppleScript webarchive AppleScript webp AppleScript Wifi AppleScript XML AppleScript XML EPUB AppleScript XML OPML AppleScript XML Plist AppleScript XML RSS AppleScript XML savedSearch AppleScript XML SVG AppleScript XML TTML AppleScript XML webloc AppleScript XMP AppleScript YouTube Applications CityCode github iPhone List lsappinfo Memo Music perl PlistBuddy pluginkit postalcode ReadMe SF Symbols character id SF Symbols Entity sips Skype Slack sqlite TCC Tools Typography Video Wacom Windows zoom