Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Change l'alignement vertical du texte dans un ou plusieurs bloc texte. Permet par le fait même d'y ajouter un raccourci clavier. Lorsque la touche «MAJ» est enfoncée, la fenêtre préférence apparaît.
/*
Permet e changer l'alignemnt vertical
Change l'alignement vertical du texte dans un ou plusieurs bloc texte.
Permet par le fait même d'y ajouter un raccourci clavier.
Lorsque la touche «MAJ» est enfoncée, la fenêtre préférence apparaît.
Original idea: https://snipt.net/certainlyakey/toggle-vertical-justification-for-a-text-frame-indesign-script/
*/
nomDuScript = "Vertical alignement texte";
dateRev = "1.0 (rev.07.12.2016)";
myId = "ben@bencloutier.com";
prefsFile = File("~/Library/" + nomDuScript + ".txt");
prefsRead();
myShiftKey = ScriptUI.environment.keyboardState.shiftKey;
mySelections = app.selection;
try{
for(i=0;i<mySelections.length;i++){
if (mySelections[i].hasOwnProperty("textFramePreferences")) {
if(myShiftKey == true) {
var myDialog = app.dialogs.add({name:nomDuScript + " " + dateRev});
with(myDialog.dialogColumns.add()){
with(borderPanels.add()){
with(dialogRows.add()){
staticTexts.add({staticLabel:"", minWidth:300});
}
var myRadioButtonGroup = radiobuttonGroups.add();
with(myRadioButtonGroup){
var myToggleButton = radiobuttonControls.add({staticLabel:"Change", checkedState:myTogglePref});
var myTopButton = radiobuttonControls.add({staticLabel:"Aligne Top", checkedState:myTopPref});
var myMiddleButton = radiobuttonControls.add({staticLabel:"Aligne Milieu", checkedState:myMiddlePref});
var myBottomButton = radiobuttonControls.add({staticLabel:"Aligne Bas", checkedState:myBottomPref});
}
}
}
var myResult = myDialog.show();
if(myResult == true){
try{
myTogglePref = myToggleButton.checkedState;
}catch(e){myTogglePref = true;}
try{
myTopPref = myTopButton.checkedState;
}catch(e){myTopPref = false;}
try{
myMiddlePref = myMiddleButton.checkedState;
}catch(e){myMiddlePref = false;}
try{
myBottomPref = myBottomButton.checkedState;
}catch(e){myBottomPref = false;}
prefsSave();
myDialog.destroy();
}else{
goOut();
}
myShiftKey = false;
}
if(myTopPref == true){
mySelections[i].textFramePreferences.verticalJustification = VerticalJustification.TOP_ALIGN;
}else if (myMiddlePref == true){
mySelections[i].textFramePreferences.verticalJustification = VerticalJustification.CENTER_ALIGN;
}else if (myBottomPref == true){
mySelections[i].textFramePreferences.verticalJustification = VerticalJustification.BOTTOM_ALIGN;
}else{
if (mySelections[i].textFramePreferences.verticalJustification == VerticalJustification.TOP_ALIGN) {
mySelections[i].textFramePreferences.verticalJustification = VerticalJustification.CENTER_ALIGN;
} else if (mySelections[i].textFramePreferences.verticalJustification == VerticalJustification.CENTER_ALIGN) {
mySelections[i].textFramePreferences.verticalJustification = VerticalJustification.BOTTOM_ALIGN;
} else if (mySelections[i].textFramePreferences.verticalJustification == VerticalJustification.BOTTOM_ALIGN) {
mySelections[i].textFramePreferences.verticalJustification = VerticalJustification.TOP_ALIGN;
}
}
}
}
}catch(selErr){
goOut("Erreur de sélection!.\nVous devez sélectionner un bloc texte avec l'outil de sélection." + "\n\n" + selErr);
}
function prefsRead(){
if(prefsFile.exists){
prefsFile.open("r");
myTogglePref = String(prefsFile.readln() );
myTopPref = String(prefsFile.readln() );
myMiddlePref = String(prefsFile.readln() );
myBottomPref = String(prefsFile.readln() );
if(myTogglePref == "true"){
myTogglePref = true;
}else{
myTogglePref = false;
}
if(myTopPref == "true"){
myTopPref = true;
}else{
myTopPref = false;
}
if(myMiddlePref == "true"){
myMiddlePref = true;
}else{
myMiddlePref = false;
}
if(myBottomPref == "true"){
myBottomPref = true;
}else{
myBottomPref = false;
}
prefsFile.close();
}else{
myTogglePref = true;
myTopPref = false;
myMiddlePref = false;
myBottomPref = false;
}
return myTogglePref, myTopPref, myMiddlePref, myBottomPref;
}
function prefsSave(){
myClosing = "Fichier préférence du script «" + nomDuScript + "» créé par " + myId + " (version " + dateRev.replace(/[()]/g,"") + ")";
try{
var mySavedPrefs =
myTogglePref + "\n" +
myTopPref + "\n" +
myMiddlePref + "\n" +
myBottomPref + "\n" +
myClosing;
if(mySavedPrefs){
prefsFile.open("w");
prefsFile.encoding = "UTF-8";//Typical values are "ASCII", "binary", or "UTF-8"
prefsFile.lineFeed = "Unix"; //One of the values "Windows", "Macintosh", or "Unix".
prefsFile.write(mySavedPrefs);
prefsFile.close();
}
}catch(e){
alert("Les preferences n'ont pus êtres sauvegardées: \n" + e);
}
}
function goOut(exitMessage){
try{
if(exitMessage){
alert(exitMessage + "\n\n" + nomDuScript + "\n" + dateRev + "\n" + myId);
}
}catch(e){}
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
app.scriptPreferences.enableRedraw = 1;
exit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment