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

JSX and doScript differences in InDesign 2022 and 2023

Contributor ,
Sep 27, 2023 Sep 27, 2023

Hi,

I am noticing an issue in the behavior of app.doScript in InDesign 2022 and 2023.

I have a jsx file that is invoked from our plugin which opens up a URL in the default browser on macOS

 

function openNativeBrowser (pUrl){
    // open the url in the default browser on Mac
    var body = [    'open location "%s"'.replace ("%s", pUrl),
                    ].join ("\r");
        
    app.doScript (body,ScriptLanguage.APPLESCRIPT_LANGUAGE);
}

 

This works well in InDesign 2022 but not in InDesign 2023 (browser does not start and even if it is started the URL is not invoked)
 
However, the following works and it opens the default browser and navigates to the URL

 

var body = ["do shell script \"open %s\"".replace("%s", pUrl)].join("\r");
app.doScript(body, ScriptLanguage.APPLESCRIPT_LANGUAGE)

 

 

So, I have three questions:

 

1. Is there a specific reason why the first code snippet does not work in InDesign 2023?

2. Is the second code snippet a better and more reliable approach?

3. The URL has several query parameters and are there any other better approaches considering this?

 

Thanks

TOPICS
How to , Scripting , SDK
1.6K
Translate
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

correct answers 1 Correct answer

Enthusiast , Sep 29, 2023 Sep 29, 2023

Right, therefore I have the impression that it is most likely an InDesign bug, as I noted in a previous post. I'm not sure if it actually is.

 

If you can solve it with a shell script, please use that to work around it.

Translate
Community Expert ,
Sep 27, 2023 Sep 27, 2023

Hi @asaxena, here's my (not expert) answers to your questions:

 

1. My guess is that something has changed with which process the applescript gets sent to. It seems to be fixed by explicitly setting this in your applescript command:

 

function openNativeBrowser(pUrl) {
    var body = 'tell app "System Events" to open location "' + pUrl + '"';
    app.doScript(body, ScriptLanguage.APPLESCRIPT_LANGUAGE);
}

 

 

2. It's hard to say. I would tend to use unix command line tools for this kind of thing because they are so easy to test (in Terminal.app for example), but really doing the applescript is easy to test too (in Script Editor.app). The unix style command can often be simpler to construct. They are both pretty standard commands, and unlikely to change in system updates. I don't think it matters which you use.

 

3. It is just a string, so just concatenate them in the normal way eg.

var url = "https://" + domain + "?parameter=" + encodeURI(myStringOrNumberParameter);

- Mark 

Translate
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
Contributor ,
Sep 29, 2023 Sep 29, 2023

Thanks. These helped me a lot

Translate
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 ,
Sep 28, 2023 Sep 28, 2023

1. Is there a specific reason why the first code snippet does not work in InDesign 2023?

 

Hi @asaxena , It also doesn’t work for me in CC2021 either. If I set pUrl to "www.google.com" and trace your body variable I get this:

 

open location "www.google.com"

 

But that doesn’t work in Apple’s ScriptEditor because as Mark points out there’s no tell block. This also works:

 

function openNativeBrowser (pUrl){
    // open the url in the default browser on Mac
    var body = [    'tell application "Safari" \r open location "%s"'.replace ("%s", pUrl),
                    ].join ("\r") + "\r end tell";
    app.doScript (body,ScriptLanguage.APPLESCRIPT_LANGUAGE);
}

 

Translate
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 ,
Sep 28, 2023 Sep 28, 2023

Hi @rob day, I noticed that if I specify the protocol, eg. "https://" in the URL, I can do

open location "https://google.com"

from Script Editor.app but it didn't work from Indesign app.doScript. You can tell "Safari", but you can also tell "Finder" and it works, too.

- Mark

Translate
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
Enthusiast ,
Sep 28, 2023 Sep 28, 2023

I tested it with a simple AppleScript.

tell application id "com.adobe.InDesign" to open location "https://www.google.com/"

 

This succeeds for InDesign 2020-2022 and fails for 2023 and 2024 (Prerelease). It also succeeds when executed in a tell block in another app outside of InDesign.

 

I was suspicious of the macOS security settings, but they seemed fine. This makes it seem more likely that it is a bug in InDesign.

Translate
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 ,
Sep 29, 2023 Sep 29, 2023

Hi @sttk3 , I don’t think you can tell InDesign to open a URL—there isn’t a location object in its AppleScript dictionary. The ID open command expects a reference to an InDesign document.

 

Screen Shot 29.png

 

The tell would have to be to an application that has the location object in its dictionary, e.g. Finder, Sytstem Events. Seems like the shell script in @asaxena’s 2nd example is the way to go because it simply uses the default browser without specifying an application.

 

Translate
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
Enthusiast ,
Sep 29, 2023 Sep 29, 2023

"open location" is a method defined in StandardAdditions and can be used anywhere in AppleScript. Of course, you can also use the shell script "open" command without "open location".

 

open location.png

Translate
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
Contributor ,
Sep 29, 2023 Sep 29, 2023

Yes, but it does not work in InDesign 2023 for me

Translate
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
Enthusiast ,
Sep 29, 2023 Sep 29, 2023

Right, therefore I have the impression that it is most likely an InDesign bug, as I noted in a previous post. I'm not sure if it actually is.

 

If you can solve it with a shell script, please use that to work around it.

Translate
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
Contributor ,
Sep 29, 2023 Sep 29, 2023

Thank you. I landed up in using the following which works for my use case:

 

 

 var body = 'tell app "System Events" to open location "' + pUrl + '"';        
 app.doScript (body,ScriptLanguage.APPLESCRIPT_LANGUAGE);

 

Translate
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
Contributor ,
Sep 29, 2023 Sep 29, 2023

Thanks. How can I get this help documentation?

Translate
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
Enthusiast ,
Sep 29, 2023 Sep 29, 2023

Open Script Editor.app and display the Window > Library panel. You will find it in.

 

Script Editor.app can be found here.

/System/Applications/Utilities/Script Editor.app

 

Translate
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 ,
Sep 29, 2023 Sep 29, 2023
LATEST

There‘s also File>Open Dictionary.

Translate
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
Mentor ,
Sep 28, 2023 Sep 28, 2023

One way to pass arguments (instead of that replace):

 

app.doScript ('tell application "System Events" to open location (item 1 of arguments)',ScriptLanguage.APPLESCRIPT_LANGUAGE,["https://www.google.com? test "]);

 

Note the additional spaces, in my Safari they arrive URL encoded.

Translate
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