• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
7

How to access ScriptLanguage.JAVASCRIPT values with AutoHotkey

Community Expert ,
Mar 01, 2024 Mar 01, 2024

Copy link to clipboard

Copied

I am trying to perform doScript using AutoHotkey and ComObject. In this case, arguments such as ScriptLanguage and UndoModes need to be specified.

 

Currently I directly write values such as 1246973031 (as ScriptLanguage.JAVASCRIPT). How do I write to get it from InDesign DOM?

 

Current code: 

app := ComObject("InDesign.Application.2024")
app.doScript("alert(0)", 1246973031, , 1699963733)

 

Ideal code: 

app := ComObject("InDesign.Application.2024")
app.doScript("alert(0)", ScriptLanguage.JAVASCRIPT, , UndoModes.ENTIRE_SCRIPT)

 

Environment: 

  • Windows 11
  • AutoHotkey 2.0
  • InDesign 2024 (19.2)
TOPICS
Scripting

Views

1.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 01, 2024 Mar 01, 2024

Copy link to clipboard

Copied

Good question! Enums aren't children of the app, they are global objects, so another way to phrase it is: how do I access ExtendScript global objects from the app — ComObject("InDesign.Application.2024")?

 

@Robert at ID-Tasker any ideas?

 

My thought would be that you will have to re-define the enums in your script. Sorry I'm no help.

- Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 01, 2024 Mar 01, 2024

Copy link to clipboard

Copied

At this point, we are not yet in ExtendScript space and expect to have access to something like idScriptLanguage.idJavascript defined in ComObject space.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 01, 2024 Mar 01, 2024

Copy link to clipboard

Copied

Did you check the tlb file with a tlb viewer it should provide some hints. Something on the app object

-Manan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2024 Mar 02, 2024

Copy link to clipboard

Copied

It looks idScriptLanguage.idJavascript is correct, but AutoHotkey gives me an error that idScriptLanguage has never been assigned a value. Do not know how to reference it.

 

idScriptLanguage.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2024 Mar 02, 2024

Copy link to clipboard

Copied

@sttk3

 

Those numeric values are only valid if you use them in the script - run as a textfile directly from the Script Pallet - or if you have VB6 installed and make a Reference to the TLB file.

 

Don't know if you can use TLB file in the AutoHotKey - I would have to Google it. 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2024 Mar 02, 2024

Copy link to clipboard

Copied

quote

@sttk3

 

[...] or if you have VB6 installed and make a Reference to the TLB file.

 

Or you can execute script from any VBA capable software - like Word / Excel, etc.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2024 Mar 02, 2024

Copy link to clipboard

Copied

Now trying to write glue code to execute doScript for InDesign from Electron or Tauri. Since the goal is to open a route, it is actually ok to write the values directly. Execution is already achieved.

 

I just wanted to find a smart way to do it like the experts know how to do. It might be to use ComObjType, ComObjValue, etc.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2024 Mar 02, 2024

Copy link to clipboard

Copied

quote

Now trying to write glue code to execute doScript for InDesign from Electron or Tauri. Since the goal is to open a route, it is actually ok to write the values directly. Execution is already achieved.

 

I just wanted to find a smart way to do it like the experts know how to do. It might be to use ComObjType, ComObjValue, etc.


By @sttk3

 

But even with a free version of my tool - you can do way more with less hassle...

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2024 Mar 02, 2024

Copy link to clipboard

Copied

Thanks @m1b.

 

@sttk3

 

What are you trying to achieve?

 

If to automate operations in InDesign - eliminate mundane clicking - then my ID-Tasker is EXACTLY what you are looking for - it performs / stimulates manual operations - so no need for external "simulation" tools.

 

You have access to ALL mouse / keyboard clicks, all the menu options - 2000+. All 400+ text properties - all 800+ object properties, tables, XML, Hyperlinks, DataMerge, etc. You can sort & filter by any property, you can work on the current selection or process multiple objects - or whole server full of documents. 

 

Simply put - similar to Actions in Photoshop - but on steroids - with a small drawback - you need to build Task manually - can't record it. Otherwise - you are only limited by your imagination. 

 

Plus you would be able to connect to other apps - Photoshop, Illustrator, Word, Excel, etc. - anything that can be controlled through VB6 / VBA. And of course online services - email, FTP, CMS, DMS, databases, ChatGPT, JSON, etc. 

Partially done but there is still a lot of things to do. 

 

Then, there is a version for InDesign Server... 

 

 

But if you prefer to do it yourself, in VBA, you can use the same numeric values as in JavaScript.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2024 Mar 02, 2024

Copy link to clipboard

Copied

@Robert at ID-Tasker, I tagged you here because I thought this might be your area of expertise. I am disappointed to see you advertising your own product, while at the same time seeming to ignore the specificity of @sttk3's question.

- Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2024 Mar 02, 2024

Copy link to clipboard

Copied

quote

@Robert at ID-Tasker, I tagged you here because I thought this might be your area of expertise. I am disappointed to see you advertising your own product, while at the same time seeming to ignore the specificity of @sttk3's question.

- Mark


By @m1b

 

All functionality I've mentioned is available for FREE - and will do more than @sttk3 needs - so I'm not sure why are you attacking me?

 

And I haven't ignored the question - I've confirmed that numeric values can be used.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2024 Mar 02, 2024

Copy link to clipboard

Copied

1. @sttk3 knows they can use the numeric values—it's literally in the sample code they provided.

2. Can you develop in your tool? ie. can someone use your tool to make something for their client?

3. My second point above is off-topic anyway.

 

Look, I respect your skill set in the VB world and that's why I tagged you here. Again (as in the other topic) I am not offended and I don't mean to offend. In this case I was disappointed and I said so, and there is no more to it. I am certainly not angry. In this case I think my reaction was mild and proportional and my criticisms are accurate.

 

We all make mis-steps and I will still gladly tag you in cases where I think your expertise will come to bear, and I hope you consider a little bit how best to market your product in future.

- Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2024 Mar 02, 2024

Copy link to clipboard

Copied

quote

2. Can you develop in your tool? ie. can someone use your tool to make something for their client?

 

It's extremely flexible - you can pretty much do whatever you want.

If you refer to adding extra, custom UI - I was thinking about that and it won't be a problem at all.

 

But if you refer to the fact that AHK is open source - no, you can't have acces to the source.

But as you can save Task(s) as a text file - you can do pretty much anything - and you can just send a txt file to your client, so, in a way - yes, you can develop for the client.

I was thinking about somehow encoding contents of the Task file - so there woudn't be outside market for Tasks - but then I changed my mind - if someone will be able to find clients to write Tasks for them - I still get my cut.

 

AHK can only do what you can see and click in the InDesign - I'm giving user access to all properties of all text / graphic objects - you'll never have access to this kind of information in AHK.

 

The beauty of my tool is - everything there runs on Tasks.

You have full access to all keys on the keyboard - so you can execute any Task at any moment just by keyboard shortcut - and I don't have to build extra shortcuts manager - you just need to add "[A-SC]" at the end of the name of the text file - e.g. "Rotate[A-SC].txt" - "A"= key "a", "S"=Shift, "C"=Control - there is also "A" for Alt.

You can even stack Tasks and use the same shortcut - but thanks to conditional rules - you can execute only specific Task under specific conditions - selection, location, size, etc.

 

You can even execute Tasks directly from InDesign - as I'm monitoring keyboard globally.

So in a way - I could create my own version of AHK - and control even applications without native VB support - if I want.

 

You have list of objects, texts, tables, hyperlinks, styles, etc.

You can sort and filter by any property.

So when you need to work only on specific objects - you can find them quickly and easily.

You don't have to go one-by-one like in the Find&Change - you have them on the list - doubleclick and you are there and you can process it or not.

And you can mix different search results - so you can find paragraphs that have two or more specific words - from different search queries.

 

And all this - and waaaay more - is available completely free.

 

quote

and I hope you consider a little bit how best to market your product in future.

 

As the core of the functionality of may tool is free - I'm not sure what is wrong in mentioning it?

InDesign is free for only 14 days...

 

Yes, there is a paid functionality - but the free stuff is rather extremely usefull on its own...

And you don't have to pay when you are not using it or pay extra to be able to not use it all the time.

It's not like my tool is free for limited time - if someone doesn't want to pay for the full version - they will just have to do some extra clicking - I'm not even forcing anyone for their credit card number to use it for free.

And I'll never know who is using it how and when - there is no communication between my tool and my server.

You can install it on a laptop and go where there is no internet - still free to use.

 

I always only mention free part of my tool.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2024 Mar 02, 2024

Copy link to clipboard

Copied

You are allowed to mention a paid product, even your own, so long as it is absolutely applicable. In this case it clearly isn't, and I am quite surprised that you do not see this.

 

Your answer to my question number 2 is "No" although you avoid saying so explicitly, and instead spent many more words advertising your product further.

 

If you think your product may be applicable, then start with presenting a clear workflow or use case, eg. using my tool you will be able to <solve your specific problem> by doing <step 1, step 2, etc>. Then you will know if the free or paid version is required. In sttk3's case here, we have no idea what they are actually working on, and advertising *any* product—without understanding how it would likely be applied in context—comes across as in poor taste.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2024 Mar 02, 2024

Copy link to clipboard

Copied

Thank you all for your replies. They have been very helpful.

 

@m1b understood exactly what I was asking and clarified the issue. The expert you called is someone I thought might be familiar with it as well.

 

@Manan Joshi made me aware of the tlb file and its viewer. I did not know what it was, but now I can perceive and observe it. Maybe the InDesign Reference for UXP is based on it or has a common ancestor.

 

@Robert at ID-Tasker brought to my attention the important fact that VB also builds enums by reference to a tlb file or something else. For example, looking at indesign-scripting-python, it seems to keep static values in the project. So it's not too bad to duplicate and keep the static value, but if AutoHotkey can execute a doScript it is referencing a tlb, which is probably expected to be accessible in some way.

 

As I indicated above, I'm looking for a deeper understanding. I would be more than willing to focus on the insights/knowledge you gained while developing the tool rather than presenting a completed tool.

 

Thank you in advance for your continued support.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2024 Mar 02, 2024

Copy link to clipboard

Copied

quote

You are allowed to mention a paid product, even your own, so long as it is absolutely applicable. In this case it clearly isn't, and I am quite surprised that you do not see this.

 

Your answer to my question number 2 is "No" although you avoid saying so explicitly, and instead spent many more words advertising your product further.

 

If you think your product may be applicable, then start with presenting a clear workflow or use case, eg. using my tool you will be able to <solve your specific problem> by doing <step 1, step 2, etc>. Then you will know if the free or paid version is required. In sttk3's case here, we have no idea what they are actually working on, and advertising *any* product—without understanding how it would likely be applied in context—comes across as in poor taste.


By @m1b

 

My assumption was that as sttk3 wants to automate some operation(s) in InDesign - is working on Windows and AHK is only available for Windows - so whatever it would be, whatever the script would have to do - using AHK is rather cumbersome - that's why I've suggested my tool.

 

Yes, we don't know exactly what sttk3 wants to do - but I can blindly say that whatever it would be - my tool will do this better.

Maybe I'll have to add some extra rule(s) - I'm more than happy to do that and won't charge extra for that - but it still will be much more convenient than simulating using AHK.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2024 Mar 02, 2024

Copy link to clipboard

Copied

quote

Yes, we don't know exactly what sttk3 wants to do - but I can blindly say that whatever it would be - my tool will do this better.

 

I'm of course in no way referring to the level of the sttk3's knowledge about VBA or JS - but to the way AHK works.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 03, 2024 Mar 03, 2024

Copy link to clipboard

Copied

The global object @m1b suggested is called "Assembly" (name choice by Microsoft), or eventually "interop assembly". Plural "assemblies" gets you closer in Google search while "assembly language" is a different beast. From the assembly you can list types, eventually descend into enumerations and enumerator.

This is similar to the Reflection feature of ExtendScript.

Maybe InDesign supports these mechanisms so that VBA can bypass the TLB, but I haven't looked at either VBA or COM in a decade.

 

AHK has limited built-in support to call named methods on COM objects that support the interface IDispatch. Without giving it a try myself, I fear you will end up calling methods by offset within other interfaces. The COM-Classes project has a bunch of examples for wrappers on such interfaces, but I haven't seen the Assembly covered there.

 

Note that the TLB is dynamically generated by InDesign to account for additions by C++ plug-ins, but this process sometimes fails. Eventually you will find old forum messages that suggest running as admin once. This becomes relevant if you distribute the resulting code, as your AHK won't be compiled, unlike Robert's glorious tool where reading the TLB is done by the IDE on compile time.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 03, 2024 Mar 03, 2024

Copy link to clipboard

Copied

Thanks for the information.

It seems the cost is too high for what I want to do. I had imagined something that could be done immediately if knew about it. I will keep it in mind as knowledge for now.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 04, 2024 Mar 04, 2024

Copy link to clipboard

Copied

Maybe you should switch to InDesign Server? 

 

The licence isn't so expensive and you'll avoid all the workarounds and simulations.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 04, 2024 Mar 04, 2024

Copy link to clipboard

Copied

InDesign Server is overkill if you remote control an existing InDesign Desktop installation on your local desktop machine. @sttk3 mentioned Electron and Tauri. I imagine a scenario of embedding InDesign into a larger application frame, e.g. what we had with OLE ages ago. To me this is a sign that UXP is not yet seen either as possible alternative (for UI limitations?), or solution (one could use it to turn InDesign into a local web service, rather than using binary COM technology).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 04, 2024 Mar 04, 2024

Copy link to clipboard

Copied

@Dirk Becker

 

But desktop version can't be used in that way - as a Web service...

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 04, 2024 Mar 04, 2024

Copy link to clipboard

Copied

> a scenario of embedding InDesign into a larger application frame

Yes, that's right. I can already integrate Illustrator and Photoshop into those workflows.

 

By having an external app perform the main process, it is possible to use existing technology to achieve stable collaboration. Also, external libraries are utilized, such as using sharp for image processing and using zip compression libraries.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 04, 2024 Mar 04, 2024

Copy link to clipboard

Copied

LATEST
quote

@Dirk Becker

 

But desktop version can't be used in that way - as a Web service...

 


By @Robert at ID-Tasker

 

Just checked EULA - and can't find this part:

 

RobertTkaczyk_0-1709596834241.png

 

Can anyone confirm if it has been permanently removed and no longer apply??

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines