Indesign frames to Numbers

Hi.

I’ve put together the script below, that takes every frame in an Indesign document and copy it’s content to an opened Numbers file, including the page number of each text in the first column.

Thanks,
Luiz

tell application "Adobe InDesign 2020"
	
	set myDoc to active document
	set myPages to every page of myDoc
	set myitemCounter to 1
	set linhaFinal to 2
	
	repeat with p from 1 to count of myPages
		tell page p of myDoc
			set totalF to the count of text frames -- count text frames on the page
			
			repeat with pFrames from 1 to totalF -- repeat in all text frames
				tell text frame pFrames
					set myitems to (every paragraph)
					
					repeat with i from 1 to count of pFrames
						set myPageNumber to name of parent as string -- get page number
						
						tell application "Numbers"
							activate
							tell table 1 of active sheet of document 1
								
								set linhaInicial to linhaFinal
								set celulaInicial to "B"
								set theText to myitems as string
								set theTextPage to "Page " & (p) as string
								
								-- add rows ------- 
								set thisRangeName to "B" & linhaInicial
								add row below row thisRangeName
								set thisRangeName to "B" & linhaInicial + 1
								set value of cell thisRangeName to theText
								
								set thisRangeName to "A" & linhaInicial + 1
								set value of cell thisRangeName to theTextPage
								set linhaFinal to (linhaInicial + 1)
								
								-------------------------------------------
								
							end tell
						end tell
						set myitemCounter to myitemCounter + 1
					end repeat
				end tell
			end repeat
		end tell
	end repeat
end tell



I believe, of course, that this script works. And the idea is also not bad. Sure, your script is useful. And congratulations on a good start. Because by the syntax of the script, I see that you are a beginner, although you have already advanced quite far.

But forum Code Exchange, is intended for ready-made + effective solutions. I won’t say that your script is bad. It’s good. But for this forum it isn’t enough good. It must not contain unnecessary variables (that is, not used more than at 1 code line), redundant code, redundant repeat loops, multiple “Numbers” activations in the repeat loop, nested tell blocks to other applications. Also, repeat loops are best done directly by elements (and not by theire indexes) where possible .

To get the text (and not paragraphs like yours) of page frames from InDesign, here it is better in the form of a list of lists. Unfortunately, I uninstalled InDesign, so I only wish you someone else can help you improve the script significantly.

NOTE: having list of list you can set whole range of cells to list directly. This way you avoid redundant repeat loop. I don’t tried in the Numbers to set a range of cells directly to list of lists. Maybe, it works too.

Hi KniazidisR.

It’s not for you or any anyone else to say what’s good enough to go in any of the fora here. luizdsilveira has offered some code which he hopes others may find interesting or useful and, if it works, that qualifies it to be in Code Exchange. If you can produce something better, by all means demonstrate this, but don’t say the offered code’s not good enough to be in the forum.

Hi.

Thank you KniazidisR, I understand and you are right. No problem and do not get offended. I agree the script can be better but my idea is to share it as a start point if some people have the same problem, as Nigel Garvey said.

Again, you are right, thank you for your message.

And Nigel Garvey, thank you for the support. I always come to MacScripter exactly to find a least one thing similar to what I need and start from there. Thank you again. I hope I can share better scripts in the near future and help people as they help me.

Thanks,
Luiz

I wish you further success and new ideas, and I will take into account a fair comment from the moderator.

Thank you. I’ll do better the next time.