AppleScript NSColor

画像のカラースペースを取得


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application


############################
### ダイアログ
############################
set appFileManager to refMe's NSFileManager's defaultManager()
###デフォルトロケーション
set ocidUserDocumentPathArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopPathURL to ocidUserDocumentPathArray's firstObject()
set aliasDefaultLocation to (ocidDesktopPathURL's absoluteURL()) as alias
#####ダイアログを前面に
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
####ダイアログを出す
set listUTI to {"public.image"} as list
set listAliasFilePath to (choose file with prompt "ファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles, showing package contents and multiple selections allowed) as list

############################
####選んだファイルパスの数だけ繰り返し
############################
repeat with itemAliasFilePath in listAliasFilePath
  ##入力パス
  set strFilePath to (POSIX path of itemAliasFilePath) as text
  set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
  ###########################
  ###【1】元イメージ
  ###読み込むイメージURL
  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
  ##NSIMAGEに読み込む
  set ocidReadImage to (refMe's NSImage's alloc()'s initWithContentsOfURL:(ocidFilePathURL))
  ##BitMapRepに変換
  set ocidReadImageRepArray to ocidReadImage's representations()
  set ocidReadImageRep to (ocidReadImageRepArray's objectAtIndex:0)
  ##ピクセルサイズ取得
  set ocidColorSpace to ocidReadImageRep's colorSpace()
  set ocidColorSpaceName to ocidReadImageRep's colorSpaceName()
log ocidColorSpaceName as text
  #
  set strColorName to ocidColorSpace's localizedName as text
  set numColorNO to ocidColorSpace's colorSpaceModel as integer
log strColorName
log numColorNO
  (*
https://quicktimer.cocolog-nifty.com/icefloe/2024/02/post-38db59.html
  
NSColorSpaceModelUnknown(0): 未知のカラーモデル
NSColorSpaceModelGray(1): グレースケールカラーモデル
NSColorSpaceModelRGB(3): RGBカラーモデル
NSColorSpaceModelCMYK(4): CMYKカラーモデル
NSColorSpaceModelLAB(5): CIELABカラーモデル
NSColorSpaceModelDeviceN(6): デバイスNカラーモデル
NSColorSpaceModelIndexed(7): インデックスカラーモデル
NSColorSpaceModelPattern(8): パターンカラーモデル
*)
  
  set ocidReadImage to ""
  set ocidReadImageRepArray to ""
  set ocidReadImageRep to ""
end repeat


|

NSColorSpace


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"

property refMe : a reference to current application
  (*
https://quicktimer.cocolog-nifty.com/icefloe/2024/02/post-38db59.html
  
NSColorSpaceModelUnknown(0): 未知のカラーモデル
NSColorSpaceModelGray(1): グレースケールカラーモデル
NSColorSpaceModelRGB(3): RGBカラーモデル
NSColorSpaceModelCMYK(4): CMYKカラーモデル
NSColorSpaceModelLAB(5): CIELABカラーモデル
NSColorSpaceModelDeviceN(6): デバイスNカラーモデル
NSColorSpaceModelIndexed(7): インデックスカラーモデル
NSColorSpaceModelPattern(8): パターンカラーモデル
*)

set ocidColor to refMe's NSColorSpace's deviceGrayColorSpace
log ocidColor's numberOfColorComponents as integer
(*1*)

set ocidColor to refMe's NSColorSpace's genericGrayColorSpace
log ocidColor's numberOfColorComponents as integer
(*1*)

set ocidColor to refMe's NSColorSpace's genericGamma22GrayColorSpace
log ocidColor's numberOfColorComponents as integer
(*1*)

set ocidColor to refMe's NSColorSpace's extendedGenericGamma22GrayColorSpace
log ocidColor's numberOfColorComponents as integer
(*1*)

set ocidColor to refMe's NSColorSpace's genericRGBColorSpace
log ocidColor's numberOfColorComponents as integer
(*3*)

set ocidColor to refMe's NSColorSpace's deviceRGBColorSpace
log ocidColor's numberOfColorComponents as integer
(*3*)

set ocidColor to refMe's NSColorSpace's sRGBColorSpace
log ocidColor's numberOfColorComponents as integer
(*3*)

set ocidColor to refMe's NSColorSpace's extendedSRGBColorSpace
log ocidColor's numberOfColorComponents as integer
(*3*)

set ocidColor to refMe's NSColorSpace's displayP3ColorSpace
log ocidColor's numberOfColorComponents as integer
(*3*)

set ocidColor to refMe's NSColorSpace's adobeRGB1998ColorSpace
log ocidColor's numberOfColorComponents as integer
(*3*)

set ocidColor to refMe's NSColorSpace's deviceCMYKColorSpace
log ocidColor's numberOfColorComponents as integer
(*4*)

set ocidColor to refMe's NSColorSpace's genericCMYKColorSpace
log ocidColor's numberOfColorComponents as integer
(*4*)

|

ICCプロファイルを読み込む

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.6"
use framework "Foundation"
use framework "AppKit"
use scripting additions


property refMe : a reference to current application


set strIccFilePath to "/System/Library/ColorSync/Profiles/sRGB Profile.icc"
set ocidIccFilePathStr to (refMe's NSString's stringWithString:strIccFilePath)
set ocidIccFilePath to ocidIccFilePathStr's stringByStandardizingPath
set ocidIccFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidIccFilePath isDirectory:false)
###NSDATAに読み込む
set ocidReadProfileData to refMe's NSData's alloc()'s initWithContentsOfURL:ocidFilePathURL

###カラースペース
set ocidColorSpace to refMe's NSColorSpace's alloc()'s initWithICCProfileData:ocidReadProfileData

|

[NSCloro]色を指定する

#!/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 ocidSetColor to refMe's NSColor's greenColor()
log ocidSetColor
log className() of ocidSetColor as text
log ocidSetColor's redComponent()
log ocidSetColor's greenComponent()
log ocidSetColor's blueComponent()
log ocidSetColor's alphaComponent()
(*
blackColor()
blueColor()
brownColor()
cyanColor()
grayColor()
greenColor()
lightGrayColor()
magentaColor()
orangeColor()
purpleColor()
redColor()
whiteColor()
yellowColor()
*)

##白黒
set ocidSetColor to refMe's NSColor's colorWithWhite:1.0 alpha:1.0
log ocidSetColor
log className() of ocidSetColor as text
log ocidSetColor
log className() of ocidSetColor as text
log ocidSetColor's whiteComponent()
log ocidSetColor's alphaComponent()
##CMYK指定の場合の場合はこちら
set ocidSetColor to refMe's NSColor's colorWithDeviceCyan:1.0 magenta:0 yellow:0 black:0 alpha:1.0
log ocidSetColor
log className() of ocidSetColor as text
log ocidSetColor's cyanComponent()
log ocidSetColor's magentaComponent()
log ocidSetColor's yellowComponent()
log ocidSetColor's blackComponent()
log ocidSetColor's alphaComponent()
###RGB系 DeviceRGB
set ocidSetColor to refMe's NSColor's colorWithDeviceRed:1.0 green:0.0 blue:0.0 alpha:1.0
log ocidSetColor
log className() of ocidSetColor as text
log ocidSetColor's redComponent()
log ocidSetColor's greenComponent()
log ocidSetColor's blueComponent()
log ocidSetColor's alphaComponent()

###RGB系 DisplayP3
set ocidSetColor to refMe's NSColor's colorWithDisplayP3Red:1.0 green:0.0 blue:0.0 alpha:1.0
log ocidSetColor
log className() of ocidSetColor as text
log ocidSetColor's redComponent()
log ocidSetColor's greenComponent()
log ocidSetColor's blueComponent()
log ocidSetColor's alphaComponent()

### Hue
set ocidSetColor to refMe's NSColor's colorWithHue:1.0 saturation:0.0 brightness:0.0 alpha:1.0
log ocidSetColor
log className() of ocidSetColor as text
log ocidSetColor's hueComponent()
log ocidSetColor's saturationComponent()
log ocidSetColor's brightnessComponent()
log ocidSetColor's alphaComponent()

|

その他のカテゴリー

Acrobat Acrobat Annotation Acrobat Dialog Acrobat Form Acrobat JS Acrobat Open Acrobat Plugin Acrobat python Acrobat Reader Acrobat Sequ Acrobat Stamps Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin System Information Admin Tools Admin Users Admin Volumes Adobe Apple AppleScript AppleScript Guide AppleScript Accessibility AppleScript AppKit AppleScript Applications AppleScript AppStore AppleScript Archive AppleScript Attributes AppleScript Automator AppleScript AVAsset AppleScript AVconvert AppleScript AVFoundation AppleScript AVURLAsset AppleScript BackUp AppleScript Barcode AppleScript Bash AppleScript Basic AppleScript Basic Path AppleScript Bluetooth AppleScript BOX AppleScript Browser AppleScript Calendar AppleScript CD/DVD AppleScript Choose AppleScript Chrome AppleScript CIImage AppleScript CloudStorage AppleScript Color AppleScript com.apple.LaunchServices.OpenWith AppleScript Console AppleScript Contacts AppleScript CotEditor AppleScript CURL AppleScript current application AppleScript Date&Time AppleScript delimiters AppleScript Desktop AppleScript Device AppleScript Disk AppleScript do shell script AppleScript Dock AppleScript DropBox AppleScript eMail AppleScript Encode Decode AppleScript Error AppleScript EXIFData AppleScript ffmpeg AppleScript File AppleScript Finder AppleScript Firefox AppleScript Folder AppleScript Fonts AppleScript GIF AppleScript HTML AppleScript Icon AppleScript Illustrator AppleScript Image Events AppleScript Image2PDF AppleScript ImageOptim Applescript iWork AppleScript Javascript AppleScript Jedit AppleScript Json AppleScript Label AppleScript List AppleScript locationd AppleScript LRC AppleScript LSSharedFileList AppleScript m3u8 AppleScript MakePDF AppleScript Map AppleScript Math AppleScript Microsoft AppleScript Microsoft Edge AppleScript Microsoft Excel AppleScript Mobileconfig AppleScript Mouse AppleScript Movie AppleScript Music AppleScript NetWork AppleScript Notes AppleScript NSArray AppleScript NSBitmapImageRep AppleScript NSBundle AppleScript NSCFBoolean AppleScript NSCharacterSet AppleScript NSColor AppleScript NSColorList AppleScript NSData AppleScript NSDictionary AppleScript NSError AppleScript NSEvent AppleScript NSFileAttributes AppleScript NSFileManager AppleScript NSFont AppleScript NSFontManager AppleScript NSImage AppleScript NSIndex AppleScript NSKeyedArchiver AppleScript NSKeyedUnarchiver AppleScript NSLocale AppleScript NSMutableArray AppleScript NSMutableDictionary AppleScript NSMutableString AppleScript NSNotFound AppleScript NSNumber AppleScript NSOpenPanel AppleScript NSPasteboard AppleScript NSPDFImageRep AppleScript NSpoint AppleScript NSPredicate AppleScript NSRange AppleScript NSRegularExpression AppleScript NSRunningApplication AppleScript NSScreen AppleScript NSSize AppleScript NSString AppleScript NSStringCompareOptions AppleScript NSTask AppleScript NSTimeZone AppleScript NSURL AppleScript NSURL File AppleScript NSURLBookmark AppleScript NSURLComponents AppleScript NSURLResourceKey AppleScript NSUserDefaults AppleScript NSUUID AppleScript NSView AppleScript NSWorkspace AppleScript Numbers AppleScript OAuth AppleScript ObjC AppleScript OneDrive AppleScript Osax AppleScript PDF AppleScript PDFAnnotationWidget AppleScript PDFContext AppleScript PDFDisplayBox AppleScript PDFDocumentPermissions AppleScript PDFKit AppleScript PDFnUP AppleScript PDFOutline AppleScript Photos AppleScript Photoshop AppleScript Plist System Events AppleScript PostScript AppleScript prefPane AppleScript Preview AppleScript Python AppleScript QR AppleScript QR Decode AppleScript QuickLook AppleScript QuickTime AppleScript record AppleScript Regular Expression AppleScript Reminders AppleScript ReName AppleScript Repeat AppleScript RTF AppleScript Safari AppleScript SaveFile AppleScript ScreenCapture AppleScript ScreenSaver AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript Sort AppleScript Sound AppleScript Spotlight AppleScript SRT AppleScript StandardAdditions AppleScript stringByApplyingTransform AppleScript System Events AppleScript System Settings AppleScript TemporaryItems AppleScript Terminal AppleScript Text AppleScript Text CSV AppleScript Text TSV AppleScript TextEdit AppleScript Translate AppleScript Trash AppleScript Twitter AppleScript UI AppleScript Unit Conversion AppleScript UTType AppleScript valueForKeyPath AppleScript Video AppleScript VisionKit AppleScript Visual Studio Code AppleScript webarchive AppleScript webp AppleScript Wifi AppleScript XML AppleScript XML EPUB AppleScript XML OPML AppleScript XML Plist AppleScript XML RSS AppleScript XML SVG AppleScript XML TTML AppleScript XML webloc AppleScript YouTube AppleScript Zero Suppress Applications Barcode OnLine Tools CityCode Design iPhone List Logs lsappinfo Memo Music perl PlistBuddy pluginkit postalcode ReadMe SF Symbols character id SF Symbols Entity sips Skype Slack sqlite TCC Tools Typography Video Wacom zoom