NSPredicate

[predicateWithFormat]基本

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
CONTAINSとMATCHES
-->パターンマッチ
BEGINSWITH ENDSWITH
-->完全一致
IN
-->リストやレコードに対して
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 strRegPattern to "[0-9]+"

set codiPridic to refMe's NSPredicate's predicateWithFormat_("(SELF MATCHES %@)", strRegPattern)

set codiPridic to refMe's NSPredicate's predicateWithFormat:"(SELF MATCHES \"[0-9]+\")"


set strArgText to "0123456789"
set boolArgText to codiPridic's evaluateWithObject:strArgText
log boolArgText
-->TRUE

set strArgText to "A0123A456789A"
set boolArgText to codiPridic's evaluateWithObject:strArgText
log boolArgText
-->FALSE

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
CONTAINSとMATCHES
-->パターンマッチ
BEGINSWITH ENDSWITH
-->完全一致
IN
-->リストやレコードに対して
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 strRegPattern to "0"

set codiPridic to refMe's NSPredicate's predicateWithFormat_("(SELF BEGINSWITH %@)", strRegPattern)


set strArgText to "0123456789"
set boolArgText to codiPridic's evaluateWithObject:strArgText
log boolArgText
-->TRUE

set strArgText to "A0123A456789A"
set boolArgText to codiPridic's evaluateWithObject:strArgText
log boolArgText
-->FALSE

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
CONTAINSとMATCHES
-->パターンマッチ
BEGINSWITH ENDSWITH
-->完全一致
IN
-->リストやレコードに対して
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 strRegPattern to "9"

set codiPridic to refMe's NSPredicate's predicateWithFormat_("(SELF ENDSWITH %@)", strRegPattern)


set strArgText to "0123456789"
set boolArgText to codiPridic's evaluateWithObject:strArgText
log boolArgText
-->TRUE

set strArgText to "A0123A456789A"
set boolArgText to codiPridic's evaluateWithObject:strArgText
log boolArgText
-->FALSE

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
error number -128
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 strRegPattern to "A*A"

set codiPridic to refMe's NSPredicate's predicateWithFormat_("(SELF LIKE %@)", strRegPattern)


set strArgText to "0123456789"
set boolArgText to codiPridic's evaluateWithObject:strArgText
log boolArgText
-->FALSE

set strArgText to "A0123A456789A"
set boolArgText to codiPridic's evaluateWithObject:strArgText
log boolArgText
-->TRUE


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
error number -128
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 strRegPattern to "D"

set codiPridic to refMe's NSPredicate's predicateWithFormat_("(SELF IN %@)", strRegPattern)


set strArgText to {"A", "B", "C"}
set ocidArgArray to refMe's NSArray's arrayWithArray:strArgText
set boolArgText to ocidArgArray's filteredArrayUsingPredicate:codiPridic
log boolArgText as list
-->{}

set strArgText to {"A", "B", "C", "D"}
set ocidArgArray to refMe's NSArray's arrayWithArray:strArgText
set boolArgText to ocidArgArray's filteredArrayUsingPredicate:codiPridic
log boolArgText as list
-->{D}


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
CONTAINSとMATCHES
-->パターンマッチ
BEGINSWITH ENDSWITH
-->完全一致
IN
-->リストやレコードに対して
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 strRegPattern to "A"

set codiPridic to refMe's NSPredicate's predicateWithFormat_("(SELF CONTAINS %@)", strRegPattern)


set strArgText to "0123456789"
set boolArgText to codiPridic's evaluateWithObject:strArgText
log boolArgText
-->FALSE

set strArgText to "A0123A456789A"
set boolArgText to codiPridic's evaluateWithObject:strArgText
log boolArgText
-->TRUE


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
CONTAINSとMATCHES
-->パターンマッチ
BEGINSWITH ENDSWITH
-->完全一致
IN
-->リストやレコードに対して
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 strRegPattern to "0123456789"

set codiPridic to refMe's NSPredicate's predicateWithFormat_("(SELF == %@)", strRegPattern)



set strArgText to "0123456789"
set boolArgText to codiPridic's evaluateWithObject:strArgText
log boolArgText
-->TRUE

set strArgText to "A0123A456789A"
set boolArgText to codiPridic's evaluateWithObject:strArgText
log boolArgText
-->FALSE

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

(*
比較演算子:
%@:オブジェクトを表すプレースホルダ
==:等しい
!=:等しくない
>:より大きい
<:より小さい
>=:以上
<=:以下
BETWEEN:範囲内にある
例: age > 25、name == %@、price BETWEEN {100, 200}
論理演算子:
AND:論理積
OR:論理和
NOT:否定
例: age > 25 AND name == %@、NOT (category == %@ OR price > 100)
プロパティと引数の組み合わせ:
%K:キーパスを表すプレースホルダ
%@:値を表すプレースホルダ
例: %K == %@、%K BETWEEN %@

*)

|

[predicateWithFormat]正規表現で判定

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
error number -128
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 ocidRemovableName to "/dev/disk4"

###パーティションのあるデバイス
set strRegPattern to "/dev/disk[0-9]+s[0-9]+"
###CD/DVDデバイス
set strRegPattern to "/dev/disk[0-9]+"


###正規表現で判定項目を作って(マッチなら)
set codiPridic to refMe's NSPredicate's predicateWithFormat_("(SELF MATCHES %@)", strRegPattern)
###判定させる
set boolCD to codiPridic's evaluateWithObject:ocidRemovableName
log boolCD
-->trueならCD/DVD

|

その他のカテゴリー

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 VMware Fusion 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