-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplyNestedStyles.jsx
More file actions
86 lines (86 loc) · 2.55 KB
/
ApplyNestedStyles.jsx
File metadata and controls
86 lines (86 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//DESCRIPTION: Applies nested styles as directly applied character styles. WARNING: This script will override any character styles which are directly applied to the text with the nested styles applied, and formatting might change!
(function(){
function IsValid (obj){
var err;
try{
if(!obj){return false}
if(kAppVersion>=6){
return obj.isValid;
}
var test = obj.parent;
return true;
}
catch(err){return false;}
}
function ResetFindPrefs(){
if(kAppVersion<5){app.findPreferences = null;}
else{app.findTextPreferences = null;ResetFindChangeOptions();}
}
function ResetFindChangeOptions(){
app.findChangeTextOptions.properties = {
includeLockedStoriesForFind:false,
includeLockedLayersForFind:false,
includeHiddenLayers:false,
includeMasterPages:false,
includeFootnotes:false,
wholeWord:false,
caseSensitive:false
}
}
function GetTempColor(doc){
for(var i=0;i<doc.swatches.length;i++){
if(doc.swatches[i].label == 'harbsTempColor'){return doc.swatches[i]}
}
return doc.colors.add({label:'harbsTempColor'});
}
function GetAppColor(colorName){
for(var i=0;i<app.swatches.length;i++){
if(app.swatches[i].name==colorName){return app.swatches[i]}
}
return null;
}
if(app.documents.length==0){return}
kAppVersion = parseFloat(app.version);
var doc = app.documents[0];
if(kAppVersion<5){
var charStyles = doc.characterStyles;
}else{
var charStyles = doc.allCharacterStyles;
}
var tempDocColor = GetTempColor(doc);
var colorName = tempDocColor.name;
var tempAppColor = GetAppColor(colorName);
var removeAppColor=false;
if(!tempAppColor){
removeAppColor=true;
tempAppColor=app.colors.add({name:colorName})
}
for(var i=1;i<charStyles.length;i++){
var savedColor = charStyles[i].underlineGapColor;
var finds=undefined;
var findsLength=0;
do{
if(finds){findsLength=finds.length}
charStyles[i].underlineGapColor=tempDocColor;
ResetFindPrefs();
if(kAppVersion<5){
app.findPreferences.underlineGapColor = tempDocColor;
app.changePreferences.appliedCharacterStyle = charStyles[i];
doc.search("",false,false,'');
break;
}else{
if(kAppVersion<6){
app.findTextPreferences.underlineGapColor = tempAppColor;
}else{
app.findTextPreferences.underlineGapColor = tempDocColor;
}
app.changeTextPreferences.appliedCharacterStyle = charStyles[i];
finds = doc.changeText();
//alert(finds.length);
}
}while(findsLength!=finds.length);
charStyles[i].underlineGapColor=savedColor;
}
tempDocColor.remove();
if(removeAppColor){tempAppColor.remove()}
})();