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

JSX and doScript differences in InDesign 2022 and 2023

Contributor ,
Sep 27, 2023 Sep 27, 2023

Copy link to clipboard

Copied

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

Views

939

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

correct answers 1 Correct answer

Community Expert , 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.

Votes

Translate

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

Copy link to clipboard

Copied

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 

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

Copy link to clipboard

Copied

Thanks. These helped me a lot

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

Copy link to clipboard

Copied

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);
}

 

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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.

 

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

Copy link to clipboard

Copied

"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

 

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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);

 

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

Copy link to clipboard

Copied

Thanks. How can I get this help documentation?

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

Copy link to clipboard

Copied

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

 

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

Copy link to clipboard

Copied

LATEST

There‘s also File>Open Dictionary.

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

Copy link to clipboard

Copied

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.

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