« [fileReferenceURL]alias形式 参照先 | トップページ | [NSURLResourceKey]NSURLIsXXXXX »

[filePathURL]alias形式リードオンリー

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

property refMe : a reference to current application
property refNSString : a reference to refMe's NSString
property refNSURL : a reference to refMe's NSURL


#############################################

###デスクトップ
set strFilePath to ("~/Desktop/")
###NSStringにして
set ocidPosixPath to refNSString's stringWithString:strFilePath
##NSStringフルパスにして
set strBaseFilePath to ocidPosixPath's stringByStandardizingPath

set ocidBaseFilePath to refMe's NSURL's fileURLWithPath:strBaseFilePath
log ocidBaseFilePath as text
(*Macintosh HD:Users:ユーザー名:Desktop:*)
log className() of ocidBaseFilePath as text
(*NSURL*)




set strRelativePath to "名称未設定" as text
###NSStringにして
set ocidRelativePath to refNSString's stringWithString:strRelativePath
log ocidRelativePath as text
(*名称未設定*)
log className() of ocidRelativePath as text
(*__NSCFString*)
####パスに使える文字列を定義
set ocidNSCFCharacterSet to refMe's NSCharacterSet's URLPathAllowedCharacterSet()
####パスに使える文字列に変換
set ocidEncodedString to ocidRelativePath's stringByAddingPercentEncodingWithAllowedCharacters:ocidNSCFCharacterSet
log ocidEncodedString as text
(*%E5%90%8D%E7%A7%B0%E6%9C%AA%E8%A8%AD%E5%AE%9A*)
log className() of ocidEncodedString as text
(*__NSCFString*)



set ocidNSUrlPath to refNSURL's alloc()'s initWithString:ocidEncodedString relativeToURL:ocidBaseFilePath
log ocidNSUrlPath's |path|() as text
(*/Users/ユーザー名/Desktop/名称未設定*)
log className() of ocidNSUrlPath as text
(*NSURL*)


set ocidPathURL to ocidNSUrlPath's filePathURL()
log ocidPathURL as text
(*Macintosh HD:Users:ユーザー名:Desktop:名称未設定*)
log className() of ocidPathURL as text
(*NSURL*)

|

« [fileReferenceURL]alias形式 参照先 | トップページ | [NSURLResourceKey]NSURLIsXXXXX »

AppleScript NSURL File」カテゴリの記事