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" |
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*" set aRes2 to aStr’s isLike:"AB?" set aRes3 to aStr’s isLike:"[Aa]BC" set aRes4 to aStr’s isLike:"[Aa][Bb]C" set aRes5 to aStr’s isLike:"[^A]BC" set aRes6 to aStr’s isLike:"[^a]BC" set bStr to current application’s NSString’s stringWithString:"A1download" |
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:9 –2D Arrayには通じないらしい bArray’s doesContain:2 |
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" |
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 NSString) |
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" set bStr to current application’s NSString’s stringWithString:"あいうえお" –Japanese Hiragana bStr’s scriptingIsEqualTo:"ぁぃぅぇぉ" –Japanese Hiragana (Yo-On) set bResAS to ("あいうえお" = "ぁぃぅぇぉ") –AppleScript system treat them as *Same* (NFKC Casefold) |
ぴよまるソフトウェアが選ぶ、2018年に書いた「価値あるScript」 – AppleScriptの穴 says:
[…] ・NSObjectの各種メソッドのじっけん […]