Skip to main content

Posts

InDesign Scripting with ScriptUI: Add a TestIt Button to Play Around

Based on my previous article " InDesign Scripting with ScriptUI: How to Move Cursor and Select Text ", let's add a button to play around. The original code looks like this: // --- Last Part of UI (No Panel) --------------------------------------------- function AddCloseButton(w) { w.grpButtons = w.add('group'); w.btnClose = w.grpButtons.add('button {text: "Close"}'); w.btnClose.onClick = function () { w.close(); } } // ------------------------------------------------------- Let me add a button to select a piece of text. Below in in the listener function "TestIt", I don't add the boundary checking . You may try and modify the variables "start" and "end" to go over the boundary. And see what happens. // --- Last Part of UI (No Panel) --------------------------------------------- function AddCloseButton(w) { w.grpButtons = w.add('group'); w.grpButtons.orientation = "column"; ...

InDesign Scripting with ScriptUI: How to Move Cursor and Select Text

Based on the code pattern in my  previous article , here I’d like to show the methods to move the cursor and to select text with button click on ScriptUI. Using buttons to move cursor and to select text is useful when working with a script, which has a UI. You don’t need to move your mouse running all over the whole screen very often for doing your tasks. Most of the time, you can concentrate your mouse movement just around the UI of your script. The code is divided into 4 parts: Part 1 , from line 10 to line 28: This is the coding pattern for the modeless dialog. Part 2 , from line 37 to line 57: The main UI is created in this part. Part 3 , three groups of buttons are created here, together with the functions, which are attached to the button click event. Group 1: from line 60 to line 67, the code setups the buttons for moving cursor. from line 69 to line 118, the event listener "MoveCursor" is defined. Group 2: from line 121 to line 128, the code s...

A Programming Pattern to Create a Modeless Dialog with Adobe ScriptUI

I'd like to create a dialog box to input some special characters onto InDesign without running the dialog every time, after I clicked on some button to input characters. A modeless dialog is the choice. But I got many crashes. Finally, with the sample from Adobe, I got a stable programming pattern, which works with Adobe CC. Here is the code: #targetengine session; // the above line is necessary to create a modeless dialog with // var win = new Window("palette", ...); // // refer to the sample program from Adobe: "SnpCreateDialog.jsx". // Which is usually located at the folder (Windows): // C:\Program Files (x86)\Adobe\Adobe ExtendScript Toolkit CC\SDK\Samples\javascript function AModelessDialog() { this.windowRef = null; } function setupWindow() { var ww = new Window("palette", "A Modeless Dialog"); addComponents(ww); return ww; } AModelessDialog.prototype.run = function() { var win = setupWindow(); this.windowRef = win; w...

Try to Add a Language Support to Prism

I try to add a language support to Prism, and I find a way to do so easly. The design of Prism allows a programmer to develop its functionality with the development environment of browsers. It also supports the development with Node.js. I don't have experience with the browser environment. That why I try to use Node.js first. Using Node.js to develop the plugin and language support allows me work with IDE without lost my familiar debugging steps: break points, watchs, call stacks, ... . I use Visual Studio Code as my IDE. Create a folder, Copy prism.js into the folder, (the prism.js is downloaded for the website of Prism) From the menu: File > Open Folder, Now the prism.js is in the Explorer of Visual Studio Code. Add a new javascript source call app.js, with the code: var loadedModule = require('./prism'); var pyCode = 'print \"Done.\"'; // a python code var result = Prism.tokenize(pyCode, Prism.languages.python); var...

Tool to Convert Source Code to HTML Encoded Text in C#

It will be convenient to have a tool converting the source code to HTML encoded text, before I can post it on my blog article. The following C# code is my tool to do the job: public FormMain() { InitializeComponent(); } private void buttonExit_Click(object sender, EventArgs e) { Close(); } private void buttonRun_Click(object sender, EventArgs e) { string src = textBoxSrc.Text; string html = System.Net.WebUtility.HtmlEncode(src); textBoxHTML.Text = html; textBoxHTML.SelectAll(); textBoxHTML.Copy(); } private void textBoxSrc_MouseClick(object sender, MouseEventArgs e) { textBoxSrc.Text = ""; } The UI: Usage: Click on the textBoxSrc, the text in textBoxSrc will be cleaned. (line 26) Copy the source code to the textBoxSrc. Click the buttonRun. The converted text will be displayed on the textBoxHTML, in the same time, the text will also be copied to the clipboard for further use. (line 13 ~ 21) You may use Visual Studio Community to create the p...

Visual Studio + Node.js: Javascript Development

In the beginning, I just planned to install a code-highlighter plugin for my Blog. After the testing on Syntaxhighlighter and Prism, I decided to add a language support of PostScript. The string data of PostScript has "(" and ")" as the deliminator: string begin and string end. According the red book: "A literal text string consists of an arbitrary number of characters enclosed in ( and ). Any characters may appear in the string other than (, ), and \, which must be treated specially. Balanced pairs of parentheses in the string require no special treatment." There are some more lines to describe about \, the "escape". I just leave them in the book. So, the issue is, I need to figure out, how to use regex to retrieve the PostScript strings from the source code to give them a color. I need to run and debug my code together with Prism (maybe Syntaxhighlighter) and to see if I can find some solution. So, I dig into finding a Javascrip...

Another Highlighter: Prism

Prism  is another highlighter, which is designed to meet the modern standard. To extend the functionality of Prism and to add a new language support for Prism are not difficult. Here are examples of three different highlighters: Prism #targetengine "session" main(); function main() { StyleSetup(); myWorking(); myCleanup(); } function StyleSetup() { var myDocument; if (app.documents.length == 0) { myDocument = app.documents.add(); } else { myDocument = app.documents.item(0); } myCompsiteFontsSetup(myDocument); } function myWorking() { } function myCleanup() { } // ===== Composite Fonts ================================== function SetupOneCompFont(myDocument, nFName, nHanName, nHanStyle, nRomName, nRomStyle) { var nCF = myDocument.compositeFonts.item(nFName); try { var myName = nCF.name; } catch (myError) { nCF = myDocument.compositeFonts.add(); with (nCF) { name = nFName; var idx; for (idx = 0; idx < 3; idx++) { //console.log(...