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);
}
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
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.
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
Copy link to clipboard
Copied
Thanks. These helped me a lot
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);
}
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
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.
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.
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.
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".
Copy link to clipboard
Copied
Yes, but it does not work in InDesign 2023 for me
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.
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);
Copy link to clipboard
Copied
Thanks. How can I get this help documentation?
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
Copy link to clipboard
Copied
There‘s also File>Open Dictionary.
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.