Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

parameter pass from applescript to javascript

Participant ,
Aug 07, 2020 Aug 07, 2020

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

TOPICS
Scripting
2.2K
Translate
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 , Aug 07, 2020 Aug 07, 2020

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.");
...
Translate
Adobe
Community Expert ,
Aug 07, 2020 Aug 07, 2020

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
Translate
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
Participant ,
Aug 14, 2020 Aug 14, 2020

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

Translate
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
Participant ,
Aug 14, 2020 Aug 14, 2020

Is threre anything wrong in the below declaration:

 

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

 

Translate
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 14, 2020 Aug 14, 2020
LATEST

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
Translate
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