-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8a9de35
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# TXT and JSON to Mac CLR converter | ||
|
||
This script can be used convert TXT and JSON files to an Apple Mac .clr color palette file. | ||
|
||
## Examples | ||
|
||
### TXT | ||
|
||
|
||
* [Html2Clr](https://github.com/ramonpoca/ColorTools) | ||
|
||
``` | ||
#0ff aqua | ||
#8B008B darkmagenta | ||
#0003 Black 20% | ||
``` | ||
|
||
### JSON | ||
|
||
Compatible with: | ||
|
||
* [eip/JSON To CLR.applescript.js](https://gist.github.com/eip/3837dfdaeb0326d44cf60c65f59e74c2) | ||
* [IORoot/macos__json2clr--convert](https://github.com/IORoot/macos__json2clr--convert) | ||
|
||
```json | ||
{ | ||
"aqua": "#0ff", | ||
"darkmagenta": "#8B008B", | ||
"Black 20%": "#0003" | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
ObjC.import('AppKit'); | ||
|
||
var app = Application.currentApplication() | ||
app.includeStandardAdditions = true | ||
|
||
var input = app.chooseFile({ofType: ["txt", "json"]}) | ||
var name = input.toString().match(/.+\/([^.]+)/)[1] | ||
var output = app.chooseFileName({ defaultName: name + '.clr' }) | ||
var contents = app.read(input) | ||
var nsclrlist = $.NSColorList.alloc.initWithName(name); | ||
var colors = [] | ||
|
||
if (contents[0] == "{") { | ||
colors = JSON.parse(contents) | ||
colors = Object.keys(colors).map(s => ({ name: s, color: colors[s] })) | ||
} else { | ||
colors = contents.split("\n") | ||
colors = colors.map(str => str.match(/(\S+)\s+(.+)/)) | ||
colors = colors.filter(match => match) | ||
colors = colors.map(match => ({ name: match[2], color: match[1] })) | ||
} | ||
colors.forEach(o => { | ||
if (o.color.startsWith("#")) | ||
o.color = o.color.substring(1) | ||
if (o.color.length < 6) | ||
o.color = o.color.split('').reduce((str, hex) => str + hex + hex, '') | ||
o.color += 'ff' | ||
; [o.r, o.g, o.b, o.a] = o.color.match(/../g).map(hex => parseInt(hex, 16) / 255) | ||
}) | ||
|
||
colors.forEach((o, i) => o.nscolor = $.NSColor.colorWithCalibratedRedGreenBlueAlpha(o.r, o.g, o.b, o.a)) | ||
colors.forEach((o, i) => nsclrlist.insertColorKeyAtIndex(o.nscolor, o.name, i)) | ||
nsclrlist.writeToFile(output.toString()); |