Copy link to clipboard
Copied
Hi all,
We are trying to get an argument using applescript and following code gives us an error. The thing I should emphasize is, this error only occurs when our plugin is installed. (My company develops a InDesign plugin and this piece of code doesn't even interact with our scripting functions). I checked our script providers and all the related implementation. Couldn't find something that blocks AppleScript. Other applescript that we call through same mechanism, doesn't have this problem. Only this "item 1 of argument" part. Any pointer would be helpful.
Code:
function functionName(ourInputArg) {
var inputArg = [ourInputArg];
var myAppleScript = 'do shell script "echo " & item 1 of arguments'
app.doScript(myAppleScript, ScriptLanguage.APPLESCRIPT_LANGUAGE, inputArg, UndoModes.FAST_ENTIRE_SCRIPT, "undo AppleScript");
}
Error:
Copy link to clipboard
Copied
and what exactly do you pass as ourInputArg? can you log item 1 of ourInputArg and see what it shows?
also shouldn't it be item 1 of our inputArg instead of item 1 of arguments?
Copy link to clipboard
Copied
Hi @leo.r ,
Thanks for your response. Here's a working sample. It suppose to read the currently opened document name. Error I'm getting is "Can't get 1 of Arguments. Access not allowed". Once I remove my plugin, this doesn't give an error
if(app.documents.length > 0){
var myName = app.documents[0].name.substr(0,app.documents[0].name.lastIndexOf("."));
myFunction(myName);
}
else{
alert("No documents are open");
}
function myFunction(ourInputArg) {
var inputArg = [ourInputArg];
var myAppleScript = 'display dialog item 1 of arguments'
app.doScript(myAppleScript, ScriptLanguage.APPLESCRIPT_LANGUAGE, inputArg, UndoModes.FAST_ENTIRE_SCRIPT, "undo AppleScript");
}
Thank you
Copy link to clipboard
Copied
Does your plug-in provide its own AppleScript support for the plug-in functionality?
Also, do other calls to arguments (for example, count arguments, arguments as string, return arguments) return an error, or only when retrieving the items?
Copy link to clipboard
Copied
If this error occurs only when the plugin in installed then I would say start by commenting out code in the plugin to identify which piece is causing this trouble and then we can discuss more with the specific information you uncover doing this.
-Manan
Copy link to clipboard
Copied
Hi @Manan Joshi ,
Thanks for the insight. Actually our plugin is way too big to be commented out. However, I put some debugging info on our plugin model's script providers. Tying to get some information from them. I'll post the updates here if I an uncover something.
Copy link to clipboard
Copied
Hi @Kasun_Bamu , I don’t get the error. Maybe something about your MacOS version and the shell script. This also, works for me:
functionName("Hello World")
function functionName(ourInputArg) {
var inputArg = [ourInputArg];
var myAppleScript = 'display dialog item 1 of arguments'
app.doScript(myAppleScript, ScriptLanguage.APPLESCRIPT_LANGUAGE, inputArg, UndoModes.FAST_ENTIRE_SCRIPT, "undo AppleScript");
}
Copy link to clipboard
Copied
Hi @rob day ,
Thanks for your effort and response. But you shouldn't be getting the error though. This error only occurs when our plugin is installed. That's what I'm trying to figure out.
Copy link to clipboard
Copied
What are you trying to do with AppleScript that can't be done with ExtendScript? Are you trying to communicate with other MacOS apps?
Copy link to clipboard
Copied
Have a look at the ourInputArg argument - use a debugger and set a breakpoint at the ExtendScript side, or add this line before the app.doScript:
alert(inputArg.toSource());
On your second example - is the document already saved?