データのclassを求めるAppleScriptです。
AppleScriptではもともと、
class of 変数
で、変数に入っているデータのclassが求められます。ただ、CocoaのオブジェクトのClassは求められないので、このようなScriptを書いてみた次第です。
AppleScript名:データのClassを求める |
use AppleScript version "2.4" use scripting additions use framework "Foundation" set theValue to "10" set aClass to getClassFromData(theValue) of me –> "text" set cRes to getClassFromData(current application’s NSArray’s arrayWithArray:{1, 2, 3}) of me –> "NSArray" tell application "System Events" set a to process "Finder" end tell set dClass to getClassFromData(a) of me –> "application process" tell application "Safari" if running then if (count of every document) > 0 then set a to front document set eClass to getClassFromData(a) of me –> "document" end if end if end tell on getClassFromData(aData) set aRes to (count {aData} each reference) if aRes = 0 then –Pure AppleScript Object try return (class of aData) as string on error return false end try else –NSObject set nsObjRes to getClassNameStringFromObject(aData) of me if nsObjRes = false then –Maybe application Object return (class of aData) as string else return nsObjRes –NSObject end if end if end getClassFromData on getClassNameStringFromObject(aObject) set classList to {"AddressBook", "AVAsset", "AVAssetExportSession", "AVAudioPlayer", "CGPointZero", "CGPostMouseEvent", "CIColor", "CIFilter", "CIImage", "CIVector", "CLLocation", "CLLocationManager", "CWInterface", "EKAlarm", "EKEventStore", "EKStructuredLocation", "FSEvent", "IOBluetoothDevice", "IOBluetoothHostController", "ITLibrary", "JSContext", "MKMapView", "Myriad Helpers", "NSAffineTransform", "NSAlert", "NSAnimationContext", "NSApp", "NSApplication", "NSArray", "NSAttributedString", "NSAutoreleasePool", "NSBezierPath", "NSBitmapImageRep", "NSBox", "NSBundle", "NSButton", "NSByteCountFormatter", "NSCalendar", "NSCharacterSet", "NSClassFromString", "NSColor", "NSColorList", "NSColorSpace", "NSColorWell", "NSComboBox", "NSCompoundPredicate", "NSCountedSet", "NSData", "NSDataDetector", "NSDate", "NSDateComponents", "NSDateFormatter", "NSDateIntervalFormatter", "NSDatePicker", "NSDecimalNumber", "NSDictionary", "NSEnergyFormatter", "NSError", "NSEvent", "NSFileManager", "NSFileSystemFreeSize", "NSFont", "NSFontCollection", "NSFontManager", "NSGraphicsContext", "NSHelpManager", "NSHomeDirectory", "NSHost", "NSImage", "NSImageView", "NSIndexSet", "NSIntersectionRect", "NSInvocationOperation", "NSJSONSerialization", "NSLengthFormatter", "NSLinguisticTagger", "NSLocale", "NSLocaleIdentifier", "NSLog", "NSMakePoint", "NSMakeRange", "NSMakeRect", "NSMapTable", "NSMassFormatter", "NSMatrix", "NSMenuItem", "NSMetadataQuery", "NSMutableArray", "NSMutableAttributedString", "NSMutableCharacterSet", "NSMutableData", "NSMutableDictionary", "NSMutableIndexSet", "NSMutableSet", "NSMutableString", "NSMutableURLRequest", "NSNetServiceBrowser", "NSNotificationCenter", "NSNumber", "NSNumberFormatter", "NSNumberFormatterRoundDown", "NSNumberFormatterRoundUp", "NSOpenPanel", "NSOperationQueue", "NSOrderedSet", "NSPasteboard", "NSPasteboardItem", "NSPipe", "NSPNGFileType", "NSPointInRect", "NSPopUpButton", "NSPredicate", "NSPrinter", "NSPrintInfo", "NSPrintOperation", "NSProcessInfo", "NSPropertyListFormat", "NSPropertyListImmutable", "NSPropertyListSerialization", "NSRange", "NSRect", "NSRegularExpression", "NSRegularExpressionAnchorsMatchLines", "NSRegularExpressionDotMatchesLineSeparators", "NSRegularExpressionSearch", "NSRunningApplication", "NSSavePanel", "NSScanner", "NSScreen", "NSScriptCommand", "NSSegmentedControl", "NSSet", "NSShadow", "NSSharingService", "NSSlider", "NSSortDescriptor", "NSSound", "NSSpeechRecognizer", "NSSpeechSynthesizer", "NSSpellChecker", "NSSplitView", "NSStatusBar", "NSString", "NSTableColumn", "NSTableView", "NSTask", "NSTextField", "NSTextView", "NSThread", "NSTimeInterval", "NSTimer", "NSTimeZone", "NSUnarchiver", "NSUnionRect", "NSURL", "NSURLComponents", "NSURLConnection", "NSURLDownload", "NSURLQueryItem", "NSURLRequest", "NSURLRequestReloadIgnoringLocalCacheData", "NSUserDefaults", "NSUTF8StringEncoding", "NSUUID", "NSView", "NSWeekCalendarUnit", "NSWindow", "NSWindowController", "NSWorkspace", "NSXMLParser", "NSZeroRect", "NSZeroSize", "ODNode", "ODQuery", "ODSession", "OSAScript", "OSAScriptController", "OSAScriptView", "PDFAnnotation", "PDFDestination", "PDFDocument", "PDFOutline", "PDFPage", "PDFThumbnailView", "PDFView", "QCView", "SBApplication", "WebView", "WKWebView"} repeat with i in classList set j to contents of i set aClass to current application’s NSClassFromString(j) try set aRes to (aObject’s isKindOfClass:aClass) as boolean on error –May be an Application Object return false end try if aRes = true then return j end repeat return false end getClassNameStringFromObject |
More from my site
(Visited 47 times, 1 visits today)