benlwong Posted July 7, 2022 Share Posted July 7, 2022 We are looking to replace Adobe InDesign. Our current system runs an external script (e.g. VB Script in Windows) that called the InDesign to merge a specific template with a data file. I know Affinity Publisher has data merge capabilities, but all the tutorials and examples require the user to open up the app manually and perform the operation. My question is is it possible to call Publisher and tell it to merge a template with a data file without human interaction? Thanks, Ben Quote Link to comment Share on other sites More sharing options...
walt.farrell Posted July 8, 2022 Share Posted July 8, 2022 Welcome to the Serif Affinity forums. 13 hours ago, benlwong said: My question is is it possible to call Publisher and tell it to merge a template with a data file without human interaction? No. It is a manual process, as described in the Help and Tutorials. Callum 1 Quote -- Walt Designer, Photo, and Publisher V1 and V2 at latest retail and beta releases PC: Desktop: Windows 11 Pro, version 23H2, 64GB memory, AMD Ryzen 9 5900 12-Core @ 3.00 GHz, NVIDIA GeForce RTX 3090 Laptop: Windows 11 Pro, version 23H2, 32GB memory, Intel Core i7-10750H @ 2.60GHz, Intel UHD Graphics Comet Lake GT2 and NVIDIA GeForce RTX 3070 Laptop GPU. iPad: iPad Pro M1, 12.9": iPadOS 17.4.1, Apple Pencil 2, Magic Keyboard Mac: 2023 M2 MacBook Air 15", 16GB memory, macOS Sonoma 14.4.1 Link to comment Share on other sites More sharing options...
lacerto Posted July 8, 2022 Share Posted July 8, 2022 Basically you can automate anything, using third party apps. But Affinity apps are not helping you in any way as there is no scripting interface and the merged data cannot be refreshed (like it can in InDesign), so you need to create a new merge document using the Publisher document that was used to set up the data merge layout, and update the data source before the merge. The following AutoHotkey (= open source utility) script shows how you could invoke Publisher with a specific Publisher document with data merge setup, open the Data Merge dialog box (Data Merge Manager), click Update, then Generate, and finally close the window. #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. ; #Warn ; Enable warnings to assist with detecting common errors. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. ;^!p:: ;Optionally create a global hotkey Run, "C:\Users\Public\Documents\Affinity\DMAutomation\TopScores.afpub", , Max UseErrorLevel if (ErrorLevel = "ERROR") MsgBox The document could not be launched. WinWaitActive, Affinity Publisher,, 30 if ErrorLevel { MsgBox, Timed out. return } else WinMaximize ; Use the window found by WinWaitActive. Send !d{Down}{Down}{Down}{Down}{Down}{Down}{Down}{Enter} ; Activate Data Merge dialog box Click, 777 449 ; Click on Update button Sleep, 1000 ; Wait for 1 second Click, 911 958 ; Click on Generate button Sleep, 5000 ; Wait for 5 seconds Send {Esc} ; Close the Data Merge dialog box return (The routine would then save the document using e.g. a specific scheme to rotate filenames and possibly creating backups, closing all documents it has opened and created.) Publisher does not make automation easy because it misses menu command and dialog control hotkeys (something that every well-crafted Windows application has), thus making automation dependent on necessity to send mouse clicks with coordinates, which is always feeble and resolution dependent. But basically it can be done: automate_datamerge.mp4 It would be possible to first invoke the Excel data source and launch Excel, which could fetch up-to-date data for the source cells from the Internet on document open event. And the AutoHotkey script could be started as a scheduled system task on a regular basis. This is of course somewhat convoluted and error prone so it requires careful planning and testing. EDIT: I am sure there are similar (free / open source) scripting solutions for macOS (Automator + AppleScript?) but I have no experience of them. Quote Link to comment Share on other sites More sharing options...
benlwong Posted August 11, 2022 Author Share Posted August 11, 2022 Thanks a lot for your in-depth reply, @lacerto! Much appreciated. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.