• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

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

Community Beginner ,
Aug 31, 2022 Aug 31, 2022

Copy link to clipboard

Copied

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
TOPICS
Scripting

Views

1.0K

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 01, 2022 Sep 01, 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/

...

Votes

Translate

Translate
Adobe
Community Expert ,
Aug 31, 2022 Aug 31, 2022

Copy link to clipboard

Copied

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 

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 Beginner ,
Aug 31, 2022 Aug 31, 2022

Copy link to clipboard

Copied

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

 

Muthu5FC5_0-1662008511880.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
Community Expert ,
Sep 01, 2022 Sep 01, 2022

Copy link to clipboard

Copied

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

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
Engaged ,
Aug 31, 2022 Aug 31, 2022

Copy link to clipboard

Copied

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/

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 ,
Aug 31, 2022 Aug 31, 2022

Copy link to clipboard

Copied

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

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 Beginner ,
Aug 31, 2022 Aug 31, 2022

Copy link to clipboard

Copied

Hi hhas,
Before i used the extended script for this file manipulations, but extendedScript file functionalities will change the created and modified time and date while we run the scripts, thats why i prefer apple script in-between which will retain the modified and created date plus time.

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
Engaged ,
Sep 02, 2022 Sep 02, 2022

Copy link to clipboard

Copied

Your problem is that if Illustratorā€™s ExtendScript API doesnā€™t provide a `doScript` function for running AppleScripts, and it doesnā€™t provide a `system()` like call for running shell scripts, and it doesnā€™t even provide a `Socket` object, then I think youā€™re about out of luck.

 

You might consider executing your .jsx scripts from AppleScript using `do javascript jsxScript with arguments {arg1, arg2, ā€¦}`, allowing AppleScript to take care of the bits you donā€™t want to do yourself. Or you might write a CEP panel, and have that execute both.

 

Personally Iā€™d just grimace and bear it for now, use `File` and `Folder` despite their limitations, and bide your time until UXP makes its public appearance for AI. UXP is built on Node.js, which is way more capable than moldy ExtendScript, in large part due to its massive third-party library support (albeit sometimes of dubious quality). That includes far better standard libraries for accessing the filesystem, and 3rd-party libraries for interacting with AppleScriptable apps directly and just about everything else.

 

Fingers crossed we all start migrating off ancient, creaky ExtendScript onto modern Node.js sooner rather than later. Letā€™s see what MAX 2022 brings in October, I guess.

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 Beginner ,
Sep 04, 2022 Sep 04, 2022

Copy link to clipboard

Copied

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šŸ˜‰!

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

Copy link to clipboard

Copied

LATEST

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-referen...

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 )

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