Cocoaの各種オブジェクトのルートクラスであるNSObjectが持っているメソッドのうち有用そうなものをAppleScriptから呼び出す実験です。
各種クラス(NSStringとかNSArrayとか)のReferenceに掲載されていないのに使えるメソッドが存在していることに、Cocoaを使い始めたころ不思議に思っていたのですが、上位クラスが持っているメソッドであることに(後になって)気づきました。
AppleScript名:isEqualTo |
— Created 2018-01-08 by Takaaki Naganoya — 2018 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aStr to current application’s NSString’s stringWithString:"ABC" aStr’s isEqualTo:"ABC" –> true aStr’s isEqualTo:"abc" –> false |
AppleScript名:isLike |
— Created 2018-01-08 by Takaaki Naganoya — 2018 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" –https://stackoverflow.com/questions/35902973/what-does-nsstrings-islike-actually-do set aStr to current application’s NSString’s stringWithString:"ABC" set aRes1 to aStr’s isLike:"AB*" –> true set aRes2 to aStr’s isLike:"AB?" –> true set aRes3 to aStr’s isLike:"[Aa]BC" –> true set aRes4 to aStr’s isLike:"[Aa][Bb]C" –> true set aRes5 to aStr’s isLike:"[^A]BC" –> true set aRes6 to aStr’s isLike:"[^a]BC" –> false set bStr to current application’s NSString’s stringWithString:"A1download" set aRes7 to bStr’s isLike:"[A-Z][0-9]" –こういう書き方は通らないらしい |
AppleScript名:doesContain |
— Created 2018-01-07 by Takaaki Naganoya — 2018 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set anArray to current application’s NSArray’s arrayWithArray:{1, 2, 3} anArray’s doesContain:1 –> true anArray’s doesContain:9 –> false –2D Arrayには通じないらしい set bArray to current application’s NSArray’s arrayWithArray:{{1, 1}, {2, 2}, {3, 3}} set cArray to current application’s NSArray’s arrayWithArray:{2, 2} bArray’s doesContain:cArray –> false bArray’s doesContain:2 –> false |
AppleScript名:instancesRespondToSelector |
— Created 2018-01-07 by Takaaki Naganoya — 2018 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" ( current application’s NSObject’s |class|())’s instancesRespondToSelector:"init"–> true |
AppleScript名:isSubclassOfClassのじっけん |
— Created 2018-01-07 12:59:32 +0900 by Takaaki Naganoya — 2018 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aStr to current application’s NSString’s stringWithString:"ABC" aStr’s superclass()’s isSubclassOfClass:(current application’s NSNumber) –> false aStr’s superclass()’s isSubclassOfClass:(current application’s NSString) –> true |
AppleScript名:superclassを求める |
— Created 2018-01-07 12:53:44 +0900 by Takaaki Naganoya — 2018 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aStr to current application’s NSString’s stringWithString:"ABC" aStr’s superclass() –> (Class) NSMutableString aStr’s superclass()’s superclass() –> (Class) NSString aStr’s superclass()’s superclass()’s superclass() –> (Class) NSObject |
(Shane Stanleyからツッコミがあって追加↓)
AppleScript名:scriptingIsEqualTo |
use AppleScript version "2.4" use scripting additions use framework "Foundation" set aStr to current application’s NSString’s stringWithString:"ABC" aStr’s scriptingIsEqualTo:"ABC" –only for NSString/NSMutableString –> true aStr’s scriptingIsEqualTo:"abc" –> true set bStr to current application’s NSString’s stringWithString:"あいうえお" –Japanese Hiragana bStr’s scriptingIsEqualTo:"アイウエオ" –Japanese Katakana –> false bStr’s scriptingIsEqualTo:"ぁぃぅぇぉ" –Japanese Hiragana (Yo-On) –> false set bResAS to ("あいうえお" = "ぁぃぅぇぉ") –AppleScript system treat them as *Same* (NFKC Casefold) –> true |