Skip to main content
Participant
August 31, 2022
Answered

app.doScript(myAppleScript, ScriptLanguage.applescriptLanguage) is not working in illustrator

  • August 31, 2022
  • 4 replies
  • 1713 views

Hi All,

I need to call a applescript inside the javascript, so i write a code like this:

var myAppleScript = 'tell application "Finder"\r';
myAppleScript += 'set myFolder to a reference to folder (name of startup disk & "' + myMacFolder + '")\r';
myAppleScript += 'set myFile to a reference to file (name of startup disk & "' + myMacFile + '")\r';
myAppleScript += 'tell myFile\r';
myAppleScript += 'duplicate to myFolder\r';
myAppleScript += 'end tell\r';
myAppleScript += 'end tell\r';
app.doScript(myAppleScript, ScriptLanguage.applescriptLanguage);

Its working fine in InDesign but if i run the same in illustrator,
its shows an error that ScriptLanguage is undefined, can anyone help me to call the apple script using do Script in illustrator javascripting.

Thanks in Advance
Muthu
This topic has been closed for replies.
Correct answer Manan Joshi

Do the following

  • Create a .command file and write a shellscript inside it using Extendscript. Command file is basically a script file that is similiar to a batch file in WIN and can be executed by double clicking on it.
  • That shell script can use the osascript command to call you applescript.
  • Execute your .command file using the execute Extendscript method.

See the following links for more information on osascript and command file

https://scriptingosx.com/2022/05/launching-scripts-4-applescript-from-shell-script/

https://www.skptricks.com/2019/08/create-executable-command-file-in-mac-os.html

-Manan

4 replies

Community Expert
June 28, 2023

Hi @Muthu5FC5 ,

found this discussion very interesting.

Thanks for all the feedback from all participants!

 

Just wanted to add an exotic alternative solution:

One could use InDesign triggered from Illustrator through ExtendScript's BridgeTalk module for doing the doScript() with the appropriate parameter. Search e.g. the InDesign forum for code samples with BridgeTalk if you are not familiar with it. Documentaion about BridgeTalk:

 

Messaging framework API reference
https://extendscript.docsforadobe.dev/interapplication-communication/messaging-framework-api-reference.html

BridgeTalk class
https://extendscript.docsforadobe.dev/interapplication-communication/bridgetalk-class.html

 

Another thing, to avoid the ugly string concatenation one could write the AppleScript code as string this way, with a "tripple-fencing" so to say:

var myAppleScriptString =
'''
tell application "Finder"

	set myFolder to a reference to folder (name of startup disk & "' + myMacFolder + '")
	set myFile to a reference to file (name of startup disk & "' + myMacFile + '")

	tell myFile
		duplicate to myFolder
	end tell

end tell
''';

 

Of course, not a very practical solution from the perspective of an arbitrary user. But an option you could consider if you run Illustrator and InDesign side by side on a machine you have full control to. Especially if you are the current user.

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Muthu5FC5Author
Participant
September 5, 2022

Thank you mananhhas and jduncan for your suggestions and options for solving this script. Right now i using manan suggestion to execute applescript as a seperate file from illustrator javascript! hope adobe will provide the feasibilities in indesign for illustrator also, that would be more smart and effeicient way to execute commands in a single call of function😉!

Inspiring
August 31, 2022

Don’t use AppleScript to manipulate files. There’s no need. ExtendScript’s built-in File and Folder objects can do that.

 

https://extendscript.docsforadobe.dev/

jduncan
Community Expert
Community Expert
August 31, 2022

I agree, and would just do all of the work within ExtendScript since you are already running it.

 

A few notes about the code below...

  • It's overly verbose since this is an explanation
  • I have used the Desktop folder since the startup volume on the new mac os is read-only (you can change it, see folder object reference below)
  • I would include some error checking to make sure the target folder exists
  • I would also check to make sure the copy location didn't already have a file by the same name as the copy method overwrites without confirmation

 

var myFolder = new Folder(Folder.desktop + "/myMacFolder/");
var myFile = new File(Folder.desktop + "/myMacFile.ai");
var myFileCopy = new File(myFolder + "/myMacFile.ai");
myFile.copy(myFileCopy);

 

Reference:

Folder Objects: https://extendscript.docsforadobe.dev/file-system-access/folder-object.html

File Objects: https://extendscript.docsforadobe.dev/file-system-access/file-object.html

Community Expert
August 31, 2022

The doScript method is Illutrator is used to play actions. See the following

https://www.indesignjs.de/extendscriptAPI/illustrator-latest/#Application.html#d1e49416__d1e50891

You could try by creating a file method to the applescript file and then calling the execute method

-Manan 

-Manan
Muthu5FC5Author
Participant
September 1, 2022

Hi Mannan,
Thanks for your logics, but if  i execute the file(apple script) using file.execute() function, its just opened in apple script editor its not running, we need to manualy triger it to run, thats the only drawback init. i think so..

var myMacFolder = myFolder.fsName.replace(/\//g, ":");
var myMacFile = myFile.fsName.replace(/\//g, ":");
var myAppleScript = 'tell application "Finder"\r';
myAppleScript += 'set myFolder to a reference to folder (name of startup disk & "' + myMacFolder + '")\r';
myAppleScript += 'set myFile to a reference to file (name of startup disk & "' + myMacFile + '")\r';
myAppleScript += 'tell myFile\r';
myAppleScript += 'duplicate to myFolder\r';
myAppleScript += 'end tell\r';
myAppleScript += 'end tell\r';


myfile1 = new File("/Users/muthvee/Desktop/Temp_Script")
myfile1.open('w');
myfile1.write(myAppleScript);
myfile1.close();
myfile1.rename("Temp_Script1.scpt")
myfile1.execute();

 

 

Manan JoshiCommunity ExpertCorrect answer
Community Expert
September 1, 2022

Do the following

  • Create a .command file and write a shellscript inside it using Extendscript. Command file is basically a script file that is similiar to a batch file in WIN and can be executed by double clicking on it.
  • That shell script can use the osascript command to call you applescript.
  • Execute your .command file using the execute Extendscript method.

See the following links for more information on osascript and command file

https://scriptingosx.com/2022/05/launching-scripts-4-applescript-from-shell-script/

https://www.skptricks.com/2019/08/create-executable-command-file-in-mac-os.html

-Manan

-Manan