Examples of handlers for NSColorList
use framework "Foundation"
use framework "AppKit"
use scripting additions
-- set thePath to POSIX path of (choose file of type {"clr"})
-- log colorListNamesFromFile(thePath)
log availableColorLists()
log colorValueFromColorListName("Blue", "Apple")
log colorListNameAllKeys("Apple")
log availableColorSpacesWithModel("NSColorSpaceModelUnknown")
log availableColorSpacesWithModel("NSColorSpaceModelGray")
log availableColorSpacesWithModel("NSColorSpaceModelRGB")
log availableColorSpacesWithModel("NSColorSpaceModelCMYK")
log availableColorSpacesWithModel("NSColorSpaceModelLAB")
log availableColorSpacesWithModel("NSColorSpaceModelDeviceN")
log availableColorSpacesWithModel("NSColorSpaceModelIndexed")
log availableColorSpacesWithModel("NSColorSpaceModelPatterned")
(**
* [Instance Method]: initWithName:fromFile:
* Initializes and returns a color list from the specified file,
* registering it under the specified name if it isn’t in use already.
*)
on colorListNamesFromFile(_path)
return ((current application's NSColorList's alloc()'s initWithName:(missing value) fromFile:_path)'s allKeys()) as list
end colorListNamesFromFile
(**
* [Type Property]: availableColorLists
* Returns an array of all color lists found in the standard color list directories.
*)
on availableColorLists()
return ((current application's NSColorList's availableColorLists())'s valueForKey:"name") as list
end availableColorLists
(**
* [Type Method]: colorListNamed:
* Searches the available color lists array and returns the color list with the specified name.
**
* [Instance Method]: colorWithKey:
* Returns the color object associated with the specified key.
**
* [Instance Method]: colorUsingColorSpace:
* Creates a new color object representing the color of the current color object
* in the specified color space.
**
* [Instance Property]: redComponent, greenComponent, blueComponent
* The red, green and blue component value of the color.
*)
on colorValueFromColorListName(_colorName, _colorListName)
set colorListName to current application's NSColorList's colorListNamed:_colorListName
set itsColor to (colorListName's colorWithKey:_colorName)'s colorUsingColorSpace:(current application's NSColorSpace's genericRGBColorSpace())
return ({(itsColor's redComponent()) * 65535 div 1, (itsColor's greenComponent()) * 65535 div 1, (itsColor's blueComponent()) * 65535 div 1})
end colorValueFromColorListName
(**
* [Type Method]: availableColorSpacesWithModel:
* Returns the list of color spaces available on the system that are displayed
* in the color panel, in the order they are displayed in the color panel.
*)
on availableColorSpacesWithModel(_colorSpace)
if (_colorSpace = "NSColorSpaceModelGray") then
return ((current application's NSColorSpace's availableColorSpacesWithModel:(current application's NSColorSpaceModelGray))'s localizedName) as list
end if
if (_colorSpace = "NSColorSpaceModelRGB") then
return ((current application's NSColorSpace's availableColorSpacesWithModel:(current application's NSColorSpaceModelRGB))'s localizedName) as list
end if
if (_colorSpace = "NSColorSpaceModelCMYK") then
return ((current application's NSColorSpace's availableColorSpacesWithModel:(current application's NSColorSpaceModelCMYK))'s localizedName) as list
end if
if (_colorSpace = "NSColorSpaceModelLAB") then
return ((current application's NSColorSpace's availableColorSpacesWithModel:(current application's NSColorSpaceModelLAB))'s localizedName) as list
end if
if (_colorSpace = "NSColorSpaceModelDeviceN") then
return ((current application's NSColorSpace's availableColorSpacesWithModel:(current application's NSColorSpaceModelDeviceN))'s localizedName) as list
end if
if (_colorSpace = "NSColorSpaceModelIndexed") then
return ((current application's NSColorSpace's availableColorSpacesWithModel:(current application's NSColorSpaceModelIndexed))'s localizedName) as list
end if
if (_colorSpace = "NSColorSpaceModelPatterned") then
return ((current application's NSColorSpace's availableColorSpacesWithModel:(current application's NSColorSpaceModelPatterned))'s localizedName) as list
end if
if (_colorSpace = "NSColorSpaceModelUnknown") then
return ((current application's NSColorSpace's availableColorSpacesWithModel:(current application's NSColorSpaceModelUnknown))'s localizedName) as list
end if
end availableColorSpacesWithModel
(**
* [Instance Property]: allKeys
* A new array containing the dictionary’s keys, or an empty array if the dictionary has no entries.
*)
on colorListNameAllKeys(_colorListName)
return ((current application's NSColorList's colorListNamed:_colorListName)'s allKeys()) as list
end colorListNameAllKeys