Skip to main content
Known Participant
September 27, 2024
Question

AppleScript combined with app.doscript() gives a permission error

  • September 27, 2024
  • 4 replies
  • 900 views

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:

This topic has been closed for replies.

4 replies

Legend
October 4, 2024

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?

rob day
Community Expert
Community Expert
September 27, 2024

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

 

Known Participant
September 30, 2024

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.

rob day
Community Expert
Community Expert
September 30, 2024

What are you trying to do with AppleScript that can't be done with ExtendScript? Are you trying to communicate with other MacOS apps?

Community Expert
September 27, 2024

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

-Manan
Known Participant
September 30, 2024

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.

leo.r
Community Expert
Community Expert
September 27, 2024

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?

Known Participant
September 30, 2024

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

leo.r
Community Expert
Community Expert
September 30, 2024

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?