Highlighted

parameter pass from applescript to javascript

Explorer ,
Aug 07, 2020

Copy link to clipboard

Copied

Could you please anyone share the codes for pass the arguments from applescript to external javascript

Adobe Community Professional
Correct answer by Charu Rajput | Adobe Community Professional

Hi raghav, Try follwing sample

Apple script

set jsFilePath to "~/Desktop/sample1.jsx"
set customArguments to "Hello"
set _name to "Test User"
with timeout of 620 seconds
	tell application "Adobe Illustrator"
		activate
		
		do javascript file jsFilePath with arguments {customArguments, _name}
		
	end tell
end timeout

 

Javascript

try {
	app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
	if (arguments.length > 0) {
		main(arguments);
	} else {
		alert("No arguments were found.");
	}
} catch (e) {
	alert("Manual Run");
	main();
}

function main(args) {
    if (typeof (args) != "undefined") {
        var message = args[0] + " "  + args[1];
        alert(message + " in Illustrator");
    }
}

 

The above code will launch Illustrator and display arguments on alert. This code is only to show interaction. To run this just run the applescript code, it will automatically open Illustrator if not open already. 

Topics

Scripting

Views

94

Likes

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

parameter pass from applescript to javascript

Explorer ,
Aug 07, 2020

Copy link to clipboard

Copied

Could you please anyone share the codes for pass the arguments from applescript to external javascript

Adobe Community Professional
Correct answer by Charu Rajput | Adobe Community Professional

Hi raghav, Try follwing sample

Apple script

set jsFilePath to "~/Desktop/sample1.jsx"
set customArguments to "Hello"
set _name to "Test User"
with timeout of 620 seconds
	tell application "Adobe Illustrator"
		activate
		
		do javascript file jsFilePath with arguments {customArguments, _name}
		
	end tell
end timeout

 

Javascript

try {
	app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
	if (arguments.length > 0) {
		main(arguments);
	} else {
		alert("No arguments were found.");
	}
} catch (e) {
	alert("Manual Run");
	main();
}

function main(args) {
    if (typeof (args) != "undefined") {
        var message = args[0] + " "  + args[1];
        alert(message + " in Illustrator");
    }
}

 

The above code will launch Illustrator and display arguments on alert. This code is only to show interaction. To run this just run the applescript code, it will automatically open Illustrator if not open already. 

Topics

Scripting

Views

95

Likes

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
Aug 07, 2020 1
Adobe Community Professional ,
Aug 07, 2020

Copy link to clipboard

Copied

Hi raghav, Try follwing sample

Apple script

set jsFilePath to "~/Desktop/sample1.jsx"
set customArguments to "Hello"
set _name to "Test User"
with timeout of 620 seconds
	tell application "Adobe Illustrator"
		activate
		
		do javascript file jsFilePath with arguments {customArguments, _name}
		
	end tell
end timeout

 

Javascript

try {
	app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
	if (arguments.length > 0) {
		main(arguments);
	} else {
		alert("No arguments were found.");
	}
} catch (e) {
	alert("Manual Run");
	main();
}

function main(args) {
    if (typeof (args) != "undefined") {
        var message = args[0] + " "  + args[1];
        alert(message + " in Illustrator");
    }
}

 

The above code will launch Illustrator and display arguments on alert. This code is only to show interaction. To run this just run the applescript code, it will automatically open Illustrator if not open already. 

Best regards

Likes

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
Reply
Loading...
Aug 07, 2020 3
Explorer ,
Aug 14, 2020

Copy link to clipboard

Copied

Hi Charu,

 This code below is part of my script to pass the argument but it wont execute. Sorry The script is too big to explain here. The concept is same need pass the argument to javascript for multiple files and multiple folder files to execute.

 

JS path

set theDocPath to path to documents folder as Unicode text

set mainaiFiles to {}

 

tell application "System Events"

set theUser to name of current user

end tell

 

set theFilesScript to theDocPath & "Adobe Scripts:scriptResources_for_illustrator_Packaging:main_library.jsx"

 

Argument passing Code

repeat with i from 1 to count of masterFilesSelected

repeat 1 times --fakeloop

set theDoc to item i of masterFilesSelected

 

set argumentCondition2 to "CollectPaths"

 

set thePath to do javascript file theFilesScript with arguments {argumentCondition2, theDoc}

 

--Check for RGB Elements, RGB Images, Opacity, Multiply

set proceed to do javascript file alias theValidationScript

if proceed is not equal to true then

display dialog "Operation Cancelled..." buttons {"OK"} default button 1

set end of cancelledFiles to theDoc

exit repeat

end if

 

set theFilePath to POSIX path of thePath as string

Likes

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
Reply
Loading...
Aug 14, 2020 0
Explorer ,
Aug 14, 2020

Copy link to clipboard

Copied

Is threre anything wrong in the below declaration:

 

set thePath to do javascript file theFilesScript with arguments {argumentCondition2, theDoc}

 

Likes

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
Reply
Loading...
Aug 14, 2020 0
Adobe Community Professional ,
Aug 14, 2020

Copy link to clipboard

Copied

Hi Ragav,

Nothing is wrong in the declaration, but I think you should activate the Illustrator application before executing the jsx script

 

Try to wrap your line as below

with timeout of 620 seconds
	tell application "Adobe Illustrator"
		activate
		set thePath to do javascript file theFilesScript with arguments {argumentCondition2, theDoc}
	end tell
end timeout

 

I mean first activate the Illustrator application and then execute your jsx script Since you are not activating, even though application is open but not active.

Best regards

Likes

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
Reply
Loading...
Aug 14, 2020 0