NSDictionary

[NSDictionary] Plistファイルの読み込み(initWithContentsOfURL)


あくまでも参考にしてください

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

サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#
005#com.cocolog-nifty.quicktimer.icefloe
006----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
007##自分環境がos12なので2.8にしているだけです
008use AppleScript version "2.8"
009use framework "Foundation"
010use scripting additions
011property refMe : a reference to current application
012
013
014#パス
015set appFileManager to refMe's NSFileManager's defaultManager()
016set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSSystemDomainMask))
017set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
018set ocidFilePathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Frameworks/CoreSpotlight.framework/Versions/A/Resources/schema.loctable") isDirectory:(false)
019#読み込み
020set listResponse to refMe's NSDictionary's alloc()'s initWithContentsOfURL:(ocidFilePathURL) |error| :(reference)
021if (item 2 of listResponse) = (missing value) then
022  log "initWithContentsOfURL 正常処理"
023  set ocidPlistDict to (item 1 of listResponse)
024else if (item 2 of listResponse) ≠ (missing value) then
025  log (item 2 of listResponse)'s code() as text
026  log (item 2 of listResponse)'s localizedDescription() as text
027  return "initWithContentsOfURL エラーしました"
028end if
029#
030
031
032
033
AppleScriptで生成しました

|

[stringWithFormat]NSDictionaryをテキストに

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

###レコード
set recordDict to {cont:"Japan", pref:"kanagawa", city:"yokohama", divisoon:"Cyuuou"} as record
###ディクショナリ
set ocidDictionary to refMe's NSDictionary's alloc()'s initWithDictionary:recordDict

set ocidRecordStr to refMe's NSString's stringWithFormat_("%@", ocidDictionary)

log ocidRecordStr as text

|

[initWithData]NSDictionaryをテキストに

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

###レコード
set recordDict to {cont:"Japan", pref:"kanagawa", city:"yokohama", divisoon:"Cyuuou"} as record
###ディクショナリ
set ocidDictionary to refMe's NSDictionary's alloc()'s initWithDictionary:recordDict


set ocidAllKeys to ocidDictionary's allKeys()

set strOutPut to "" as text

repeat with itemKeys in ocidAllKeys
    set ocidValue to (ocidDictionary's valueForKey:itemKeys)
    set strOutPut to strOutPut & (itemKeys as text) & ":" & (ocidValue as text) & "\n"
end repeat

log strOutPut as text

|

[initWithData]NSDictionaryをテキストに

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

###レコード
set recordDict to {cont:"Japan", pref:"kanagawa", city:"yokohama", divisoon:"Cyuuou"} as record
###ディクショナリ
set ocidDictionary to refMe's NSDictionary's alloc()'s initWithDictionary:recordDict
###JSONに格納
set ocidJson to refMe's NSJSONSerialization's dataWithJSONObject:ocidDictionary options:0 |error|:(reference)
###テキスト化
set ocidJsonStr to refMe's NSString's alloc()'s initWithData:(item 1 of ocidJson) encoding:(refMe's NSUTF8StringEncoding)
###出力
log ocidJsonStr as text

|

[valueForKey]レコードの値を取得

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

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

property objMe : a reference to current application
property objNSString : a reference to objMe's NSString
property objNSDictionary : a reference to objMe's NSDictionary
property objNSMutableDictionary : a reference to objMe's NSMutableDictionary

####:NSDictionary
####初期化
set ocidDictionary to objNSDictionary's dictionary()
####レーコード
set recordKeyValue to {KeyLangJP:"日本語", KeyLangEN:"英語"} as record
####レコードをNSDictionary
set ocidDictionary to objNSDictionary's dictionaryWithDictionary:recordKeyValue
####valueForKey
set ocidValue to ocidDictionary's valueForKey:"KeyLangJP"
log className() of ocidValue as text
log ocidValue as text



####:NSMutableDictionary
####初期化
set ocidNSMutableDictionary to objNSMutableDictionary's dictionary()
####レーコード
set recordKeyValue to {KeyLangJP:"日本語", KeyLangEN:"英語"} as record
####レコードをNSMutableDictionary
set ocidNSMutableDictionary to objNSMutableDictionary's dictionaryWithDictionary:recordKeyValue
####valueForKey
set ocidValue to ocidNSMutableDictionary's valueForKey:"KeyLangEN"
log className() of ocidValue as text
log ocidValue as text

return

|

[NSDictionary] NSDictionaryの初期化

#!/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 objMe : a reference to current application
property objNSString : a reference to objMe's NSString
property objNSURL : a reference to objMe's NSURL
property objNSLog : a reference to objMe's NSLog
property objNSMutableArray : a reference to objMe's NSMutableArray
property objNSMutableDictionary : a reference to objMe's NSMutableDictionary
property objNSDictionary : a reference to objMe's NSDictionary
property objNSArray : a reference to objMe's NSArray


#####通常レコード
set listValueList to {"Value1", "Value2"} as list

set listKeyList to {"Key1", "Key2"} as list


#####NSDictionary初期化
set ocidDictionary to objNSDictionary's alloc()'s init()

#####レコード=不変NSDictionary
set ocidDictionary to objNSDictionary's dictionaryWithObjects:listValueList forKeys:listKeyList

###ログ
log className() of ocidDictionary as text
--> __NSDictionaryM
log ocidDictionary as record

###値を取得
set ocidValue to Key1 of ocidDictionary
###ログ
log className() of ocidValue as text
--> NSTaggedPointerString
log ocidValue as text

|

その他のカテゴリー

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