Skip to main content
Known Participant
August 7, 2020
解決済み

parameter pass from applescript to javascript

  • August 7, 2020
  • 返信数 1.
  • 2135 ビュー

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

このトピックへの返信は締め切られました。
解決に役立った回答 Charu Rajput

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. 

返信数 1

Charu Rajput
Community Expert
Charu RajputCommunity Expert解決!
Community Expert
August 7, 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
Known Participant
August 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

Known Participant
August 14, 2020

Is threre anything wrong in the below declaration:

 

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