Last active
December 18, 2024 05:57
-
-
Save creold/9daea3ea30eeea11dd5d79609a0d0c91 to your computer and use it in GitHub Desktop.
Export a list of used Spot colors to TXT. Adobe Illustrator script
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
/* | |
The script exports a list of used Spot colors to txt | |
Author: Sergey Osokin, email: hi@sergosokin.ru | |
Check my other scripts: https://github.com/creold | |
Donate (optional): | |
If you find this script helpful, you can buy me a coffee | |
- via Buymeacoffee: https://www.buymeacoffee.com/aiscripts | |
- via Donatty https://donatty.com/sergosokin | |
- via DonatePay https://new.donatepay.ru/en/@osokin | |
- via YooMoney https://yoomoney.ru/to/410011149615582 | |
*/ | |
//@target illustrator | |
app.preferences.setBooleanPreference('ShowExternalJSXWarning', false);// Fix drag and drop a .jsx file | |
function main() { | |
if (!/illustrator/i.test(app.name)) return; | |
if (parseFloat(app.version) < 16) return; | |
var action = { | |
set: '[TEMP]', | |
name: 'CleanSwatches', | |
path: Folder.myDocuments + '/Adobe Scripts/' | |
}; | |
delUnusedSwatch(action); | |
var doc = app.activeDocument; | |
var spots = doc.spots; | |
var spotNames = ''; | |
try { | |
for (var i = 0; i < spots.length; i++) { | |
var sw = spots[i]; | |
if (/registration/i.test(sw.colorType)) continue; | |
spotNames += sw.name.replace(/PANTONE(\sP)?\s/, 'P ') + '\r\n'; | |
} | |
} catch (err) {} | |
app.redraw(); | |
app.undo(); // Restore swatches | |
var docName = doc.name.replace(/\.[^\.]+$/, ''); | |
var txt = decodeURI(doc.path) + '/' + docName + '_spots.txt'; | |
writeData(txt, spotNames); | |
alert('The names of all spot swatches have been saved to ' + txt); | |
} | |
// Add action | |
function delUnusedSwatch(action) { | |
app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS; | |
var str = [ | |
'/version 3', | |
'/name [' + action.set.length + ' ' + ascii2Hex(action.set) + ']', | |
'/isOpen 1', | |
'/actionCount 1', | |
'/action-1 {', | |
'/name [' + action.name.length + ' ' + ascii2Hex(action.name) + ']', | |
' /keyIndex 0', | |
' /colorIndex 0', | |
' /isOpen 1', | |
' /eventCount 2', | |
' /event-1 {', | |
' /useRulersIn1stQuadrant 0', | |
' /internalName (ai_plugin_swatches)', | |
' /localizedName [ 8', | |
' 5377617463686573', | |
' ]', | |
' /isOpen 1', | |
' /isOn 1', | |
' /hasDialog 0', | |
' /parameterCount 1', | |
' /parameter-1 {', | |
' /key 1835363957', | |
' /showInPalette 4294967295', | |
' /type (enumerated)', | |
' /name [ 17', | |
' 53656c65637420416c6c20556e75736564', | |
' ]', | |
' /value 11', | |
' }', | |
' }', | |
' /event-2 {', | |
' /useRulersIn1stQuadrant 0', | |
' /internalName (ai_plugin_swatches)', | |
' /localizedName [ 8', | |
' 5377617463686573', | |
' ]', | |
' /isOpen 1', | |
' /isOn 1', | |
' /hasDialog 1', | |
' /showDialog 1', | |
' /parameterCount 1', | |
' /parameter-1 {', | |
' /key 1835363957', | |
' /showInPalette 4294967295', | |
' /type (enumerated)', | |
' /name [ 13', | |
' 44656c65746520537761746368', | |
' ]', | |
' /value 3', | |
' }', | |
' }', | |
'}'].join(''); | |
try { | |
app.unloadAction(action.set, ''); | |
} catch (err) {} | |
createAction(str, action.set, action.path); | |
app.doScript(action.name, action.set); | |
app.unloadAction(action.set, ''); | |
app.userInteractionLevel = UserInteractionLevel.DISPLAYALERTS; | |
} | |
// Load action | |
function createAction(str, set, path) { | |
if (!Folder(path).exists) Folder(path).create(); | |
var f = new File('' + path + '/' + set + '.aia'); | |
f.open('w'); | |
f.write(str); | |
f.close(); | |
app.loadAction(f); | |
f.remove(); | |
} | |
// String to hex | |
function ascii2Hex(hex) { | |
return hex.replace(/./g, function(a) { | |
return a.charCodeAt(0).toString(16) | |
}); | |
} | |
function writeData(name, str) { | |
var f = new File(name); | |
f.open('w'); | |
f.write(str); | |
f.close(); | |
} | |
// Run script | |
try { | |
main(); | |
} catch (err) {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More about script in Telegram channel.