Generate contextually-aware placeholder text in Adobe InDesign using the power of ChatGPT.
Lorem Chatum is a script for Adobe InDesign that revolutionizes the way you create placeholder text. Instead of traditional static lorem ipsum, it leverages OpenAI's ChatGPT (specifically the gpt-3.5-turbo model) to generate multilingual, contextually relevant text. This helps you create more realistic and visually cohesive design mockups.
Lorem Chatum offers two primary functionalities:
- Fill Empty Text Frames: If you select an empty text frame, the script analyzes other text content on the current InDesign page to understand the context. It then prompts ChatGPT to generate new text that fits this context and the selected frame's language.
- Extend Existing Text: If you select a text frame that already contains text, Lorem Chatum uses that existing text as a starting point and asks ChatGPT to continue writing, effectively extending your current content in the same style and language.
The amount of text generated is intelligently estimated based on the selected text frame's size and its primary font size.
This tool is designed for:
- Graphic Designers
- Layout Artists
- UI/UX Designers working with print or digital layouts in InDesign
- Anyone who frequently uses placeholder text and desires something more dynamic and representative than standard lorem ipsum.
- Contextual Relevance: Generates placeholder text that aligns with the existing content on your page, making mockups look more realistic.
- Multilingual Capabilities: Supports any language that ChatGPT can handle. Simply set the desired language in InDesign's Character panel for the selected text frame.
- Improved Design Process: Helps visualize final layouts more accurately.
- Cost-Effective: While using the OpenAI API is a paid service, it's generally inexpensive for text generation. For example, processing a volume equivalent to Leo Tolstoy’s "War and Peace" (over 1,200 pages, 780k tokens) with the
gpt-3.5-turbomodel would cost approximately US$3. (Note: GPT-4 models are significantly more expensive).
To use Lorem Chatum, you must have your own OpenAI API secret key.
- Create an Account: If you don't have one, sign up at OpenAI.
- Generate a Secret Key: Navigate to the API keys section in your OpenAI account settings and create a new secret key. It will look something like
sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. - Billing: You'll also need to set up billing information in your OpenAI account. New accounts often come with some free credits, but sustained use will incur charges based on the amount of text processed (tokens).
This key will be added to the Lorem Chatum script file during installation.
First, download the latest version of the script:
➡️ Download Lorem Chatum (main.zip)
After downloading, unzip the lorem-chatum-for-indesign-main.zip file and navigate into the unzipped lorem-chatum-for-indesign-main folder. The installation steps vary depending on your Adobe InDesign version.
This version uses modern UXP JavaScript and is the actively developed version.
- License: Apache 2.0 License
The src/v2-indesign-2023-and-newer/ folder contains the script Lorem-Chatum-v2.idjs and installers.
Using Installers (Easiest Method):
- Have your OpenAI API secret key ready (copied to your clipboard).
- On macOS:
- Navigate to the
src/v2-indesign-2023-and-newer/folder. - Double-click the
install-Mac.commandfile. - A terminal window will open and prompt you to paste your OpenAI API key. Paste it and press Enter.
- The script will be automatically installed.
- Navigate to the
- On Windows:
- Navigate to the
src/v2-indesign-2023-and-newer/folder. - Double-click the
install-Win.batfile. - A command prompt window will open and prompt you to paste your OpenAI API key. Paste it and press Enter.
- The script will be automatically installed.
- Navigate to the
Manual Installation (v2):
- Open
src/v2-indesign-2023-and-newer/Lorem-Chatum-v2.idjsin a plain text editor (like VS Code, Sublime Text, or even Notepad/TextEdit). - Locate the line:
const OPENAI_API_KEY = "sk-";
- Replace
"sk-"with your actual OpenAI API secret key, keeping the quotes:const OPENAI_API_KEY = "sk-yourActualOpenAIKeyGoesHere";
- Save the file.
- Copy the modified
Lorem-Chatum-v2.idjsfile to your InDesign Scripts Panel folder. Common locations:- macOS:
~/Library/Preferences/Adobe InDesign/Version X.X/en_US/Scripts/Scripts Panel/(replaceVersion X.Xanden_USwith your version and language). - Windows:
%USERPROFILE%\AppData\Roaming\Adobe\InDesign\Version X.X\en_US\Scripts\Scripts Panel\(replaceVersion X.Xanden_USwith your version and language). - You can also find this folder by opening InDesign, going to
Window > Utilities > Scripts, right-clicking on the "User" folder in the Scripts panel, and selecting "Reveal in Finder" (macOS) or "Reveal in Explorer" (Windows).
- macOS:
This version uses the older ExtendScript and is considered legacy.
- License: GNU General Public License v3.0 (due to a dependency).
Manual Installation (v1):
- Open
src/v1-indesign-2022-and-older/Lorem-Chatum-v1.jsxin a plain text editor. - Locate the line:
const OPENAI_API_KEY = 'sk-';
- Replace
'sk-'with your actual OpenAI API secret key, keeping the quotes:const OPENAI_API_KEY = 'sk-yourActualOpenAIKeyGoesHere';
- Save the file.
- Copy the modified
Lorem-Chatum-v1.jsxfile to your InDesign Scripts Panel folder (see locations mentioned in the v2 manual installation section).
Once installed (and after restarting InDesign if it was running during installation):
- Open Adobe InDesign.
- Go to Window > Utilities > Scripts. This will open the Scripts panel.
- In the Scripts panel, expand the User section. You should see
Lorem-Chatum-v2.idjsorLorem-Chatum-v1.jsxlisted.
Scenario 1: Filling an Empty Text Frame
- Ensure you have some other text frames on your current page that contain text. This text will provide context.
- Create a new, empty text frame where you want the generated text.
- Select the empty text frame with the Selection Tool (the black arrow).
- Important: Set the desired language for the generated text. Select the text frame, then go to the Character panel (
Window > Type & Tables > Character) and choose the language from the language dropdown menu. - In the Scripts panel, double-click the
Lorem-Chatumscript. - A progress indicator may appear. The script will:
- Gather text from other frames on the current page (up to about 500 words).
- Estimate the required length based on the frame size.
- Send this context to ChatGPT, asking it to generate text in the specified language.
- Place the generated text into your selected empty frame.
Scenario 2: Extending Existing Text in a Frame
- Select a text frame that already contains some text.
- Important: Ensure the language of the existing text (and the desired language for continuation) is set correctly in the Character panel.
- In the Scripts panel, double-click the
Lorem-Chatumscript. - The script will:
- Take the existing text from the selected frame.
- Estimate how much more text is needed to fill the frame.
- Send the existing text to ChatGPT, asking it to continue writing in the same style and language.
- Append the generated text to the existing content in the frame.
You can repeat the process on the same frame. If you want more text in a frame that was filled, simply make the text frame larger and run the script again on that frame.
- Believability: The text generated by Lorem Chatum can be very authentic and believable. If you're mixing it with real content, ensure you have a system to distinguish placeholder text from final copy.
- Fact-Checking: As with all AI-generated content, do not assume the text is factually accurate or ready for publication without review. It's for placeholder and layout purposes.
- API Costs: While generally low, monitor your OpenAI API usage and associated costs, especially if using the script extensively.
This section delves into the inner workings of Lorem Chatum and provides guidelines for contributors.
While v1 (ExtendScript) and v2 (UXP) are implemented differently due to their respective environments, the core logic for interacting with InDesign and OpenAI is conceptually similar.
Core Logic (Conceptual):
-
Document & Selection Validation:
- Checks if a document is open.
- Verifies that a single text frame is selected.
- Displays an alert if these conditions aren't met.
-
Context Acquisition:
- Empty Text Frame: If the selected frame
contentsis empty, the script iterates through all other text frames on theactivePage. It concatenates their contents to form a context string. This context is capped at approximately the first 500 words to stay within reasonable limits for the OpenAI prompt. - Non-Empty Text Frame: If the selected frame already contains text, its
contentsare used directly as the prompt for OpenAI.
- Empty Text Frame: If the selected frame
-
Language Determination:
- The script reads the language applied to the first character (or the whole text if uniform) of the selected text frame:
textFrame.texts[0].appliedLanguage.name. This name (e.g., "English: USA", "Polski") is parsed to extract the base language name (e.g., "English", "Polish") which is then sent to ChatGPT.
- The script reads the language applied to the first character (or the whole text if uniform) of the selected text frame:
-
Token Estimation for OpenAI API:
- To tell ChatGPT roughly how much text to generate, the script estimates the capacity of the selected text frame. This is a heuristic based on:
- The frame's geometric bounds (width and height).
- The point size of the text (
textFrame.texts[0].pointSize). - An average character width (approximated as
fontSize * 0.6). - An average line height (approximated as
fontSize * 1.2).
- From these, it estimates the number of characters the frame can hold. This character count is then used as a loose proxy for
max_tokens. - The final
max_tokenssent to the API is capped (e.g., at 4095 forgpt-3.5-turbo) to prevent errors and excessive costs. Note: This estimation is approximate and primarily guides the length of the AI's response.
- To tell ChatGPT roughly how much text to generate, the script estimates the capacity of the selected text frame. This is a heuristic based on:
-
OpenAI API Interaction (
gpt-3.5-turbomodel):- The script makes a POST request to
https://api.openai.com/v1/chat/completions. - System Prompt: A directive is sent to guide the AI's behavior:
where
"Write an essay in [lang], to the max length, by continuing the prompt. Do not ask anything, do not add anything that is not requested."[lang]is the determined language. - User Prompt: The acquired context (from page or frame) is sent as the user's message.
- Key API Parameters Used:
model: "gpt-3.5-turbo"messages: Array containing the system and user prompts.temperature:1(for creative responses).max_tokens: The estimated number of tokens.top_p:1.n:1(requesting a single completion).frequency_penalty:0.presence_penalty:0.
- The script makes a POST request to
-
Text Insertion:
- The
contentfrom ChatGPT's response (responseData.choices[0].message.content) is retrieved. - A leading space is typically added, and any leading newline is removed.
- This generated text is appended to the
contentsof the selected InDesign text frame.
- The
Version-Specific Implementations:
-
v2 (
Lorem-Chatum-v2.idjs- UXP for InDesign 2023+)- Technology: Modern ECMAScript 6+ (ES6+) JavaScript, running in Adobe's UXP (Unified Extensibility Platform) environment.
- API Calls: Uses the native
fetchAPI for HTTPS requests to the OpenAI endpoint.let response = await fetch('https://api.openai.com/v1/chat/completions', { /* ...options... */ });
- JSON Handling: Uses native
JSON.stringify()to prepare the request body andawait response.json()to parse the OpenAI API's JSON response. - User Interface (UI):
- Dialogs for alerts and progress messages are created dynamically using UXP's DOM-like APIs (
document.createElement("dialog")) and Spectrum UXP components (<sp-body>,<sp-button>,<sp-text>).const dialog = document.createElement("dialog"); dialog.innerHTML = \`...\`; // Spectrum UXP components document.body.appendChild(dialog); dialog.showModal(); // dialog.close();
- The script detects InDesign's UI brightness (
app.generalPreferences.uiBrightnessPreference) to set dialog text color (black/white) for better visibility.
- Dialogs for alerts and progress messages are created dynamically using UXP's DOM-like APIs (
- Measurement Units: Before performing geometric calculations for token estimation, the script temporarily sets the document's
horizontalMeasurementUnits,verticalMeasurementUnits,typographicMeasurementUnits, andtextSizeMeasurementUnitstoMeasurementUnits.points. Original settings are restored afterwards. - Installers:
install-Mac.command: A Python 3 script. It interactively prompts for the OpenAI API key. It locates the latest InDesign version's Scripts Panel folder (e.g.,~/Library/Preferences/Adobe InDesign/Version X.X/en_US/Scripts/Scripts Panel/) by scanning directories and sorting by version number. It then reads theLorem-Chatum-v2.idjstemplate, replaces the placeholder API key, and writes the new file to the target Scripts Panel folder.install-Win.bat: A Windows Batch script. It also prompts for the API key. It finds the latest InDesign version folder in%USERPROFILE%\AppData\Roaming\Adobe\InDesign\. It copiesLorem-Chatum-v2.idjsto the target Scripts Panel folder and then uses aforloop withfind /n /v ""to read the script line by line, replacing the API key placeholder, and writing to a temporary file, which then replaces the original.
-
v1 (
Lorem-Chatum-v1.jsx- ExtendScript for InDesign 2022 and older)- Technology: Legacy ExtendScript (a JavaScript ES3 dialect).
- API Calls: Relies on the embedded
restix.jsxlibrary by Gregor Fellenz.Restixacts as a bridge, using VBScript (MSXML2.ServerXMLHTTP.6.0orADODB.Stream) on Windows and AppleScript (wrappingcurl) on macOS to perform the actual HTTPS request to OpenAI. - JSON Handling: Uses the embedded
json.jsxlibrary by Marc Autret. This providesJSON.lave()(similar toJSON.stringify()) andJSON.eval()(similar toJSON.parse(), but usingeval()) for constructing the request body and parsing the response. - User Interface (UI): Uses standard ExtendScript
alert()for messages. No progress dialog.
API Key Management:
- In both versions, the OpenAI API key is stored directly as a string constant within the script file (
OPENAI_API_KEY = "sk-..."). - The installer scripts for v2 automate the process of writing this key into the script. For v1 or manual v2 installation, the user must edit the script file directly.
- Security Note: Storing API keys directly in client-side scripts is generally not recommended for web applications. However, in the context of a local InDesign script run by the user, it's a pragmatic approach for ease of setup. Users should still protect their API keys.
We welcome contributions to Lorem Chatum, especially for the v2 (UXP) version!
Project Structure:
src/v1-indesign-2022-and-older/: Contains the legacy ExtendScript version (.jsx).src/v2-indesign-2023-and-newer/: Contains the modern UXP JavaScript version (.idjs) and its installers.documentation/: Contains assets like the demo GIF.
v2 (Adobe InDesign 2023 and newer - Active Development):
- This is the primary version for future development and improvements.
- License: Apache 2.0 License.
- Contributions:
- Please submit Pull Requests to the
mainbranch. - Try to follow the existing coding style and patterns.
- Ensure your changes work reliably in recent versions of InDesign (2023+).
- Please submit Pull Requests to the
- Development Tips:
- Familiarize yourself with Adobe UXP: InDesign UXP Documentation.
- The UXP Developer Tool can be helpful for debugging.
- Modern JavaScript (ES6+) features can be used.
v1 (Adobe InDesign 2022 and older - Legacy):
- This version is considered "end-of-life" and is not planned for active development. It is provided for users of older InDesign versions.
- License: GNU General Public License v3.0. This is due to its dependency on
Restix.jsx, which is GPLv3 licensed. Thejson.jsxpolyfill is MIT licensed.
Future Ideas (Contributions Welcome!):
The original author (Adam Twardoch, with help from ChatGPT-4 for v1) envisioned several potential enhancements:
- UXP Plugin: Convert the v2 script into a full UXP plugin for better integration and potential panel UI.
- Improved UI: Develop a more interactive UXP dialog/panel for settings (e.g., selecting different OpenAI models, adjusting temperature, choosing prompt styles).
- Secure API Key Storage: If developed as a UXP plugin, explore UXP's SecureStorage for storing the OpenAI API key more securely than plain text in the script.
- More Prompting Types: Allow users to select different styles of text generation (e.g., "more formal," "more creative," "bullet points").
- Improved Token Estimation: Refine the logic for estimating the number of tokens to better match the frame's capacity.
- Translation Functionality: Add a feature where if two frames are selected (one with source text, one empty target frame), the script translates the text.
- Summarization/Shortening: Add functionality to shorten or summarize text within a frame to resolve overflows.
- Author: Adam Twardoch
- The initial version (v1, ExtendScript) was written with significant assistance from ChatGPT-4.
- v1 Dependencies:
- JSON processing: standalone JSON code by Marc Autret (MIT License).
- HTTPS API calls: Restix code by Gregor Fellenz (GNU GPL v3.0).
The original README included some taglines and scenarios written by ChatGPT. These have been omitted in this version for brevity but can be found in the project's commit history if desired. The section "A few words about writing code together with ChatGPT" from the original README has also been omitted here but can be found in the commit history.
