Saturday, January 23, 2021

#1 2020-12-01 12:11:35 pm

Fredrik71
Member
Registered: 2019-10-23
Posts: 607

Pick Color Palette to been saved at ~/Library/Colors

Its very useful to save color palette to be able to pick color values. We could store this in
document folder or we could save this in ~/Library/Colors with extension (.clr)

This script will ask for Color Palette file with extension clr and save it in ~/Library/Colors
It will ask for a colorPaletteName without (.clr)
You could now open the color palette in you color picker to use in AppleScript.

Applescript:

-- Choose the color palette (colorName.clr)
set thePath to POSIX path of (choose file of type {"clr"})
set basename to display dialog "Color Palette Name without (.clr):" default answer ""
set basename to basename's text returned
set colorList to current application's NSColorList's alloc()'s initWithName:basename fromFile:thePath
-- Save to ~/Library/Colors
colorList's writeToFile:(missing value)

The writeToFile is deprecated so here is a version with wtiteToURL
https://developer.apple.com/documentati … guage=objc

Applescript:

use framework "Foundation"
use framework "AppKit"
use scripting additions

-- Choose the color palette (colorName.clr)
set thePath to POSIX path of (choose file of type {"clr"})
set basename to display dialog "Color Palette Name without (.clr):" default answer ""
set basename to basename's text returned
set colorList to current application's NSColorList's alloc()'s initWithName:basename fromFile:thePath
-- Save to ~/Library/Colors
colorList's writeToURL:(missing value) |error|:(reference)

Last edited by Fredrik71 (2020-12-03 06:40:57 am)


The purpose to study someone else art is not to add, its to make less more.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)