How to pass variables value from Applescript to Javascript?

I want to use “do script” in my applescript, but I need javascript to accept the variables which are being processed by applescript. It will prompt me error as the variables value from applescript is not being passed to javascript.

I search through the Board but found no solution on this issue. Hope someone can help me to solve this problem.


Your JavaScript is nothing more than a string of text so you should just be able to concatenate the parts together just remember that JavaScript is Zero based so you need to -1 for object values and object counts.
This should give you the basic idea.

tell application "Adobe Acrobat 7.0 Professional"
	tell active doc
		-- Get a variable from AppleScript
		set Page_Count to count of pages
		-- Concatenate into the JavaScript string
		do script "app.alert( 'This PDF has " & Page_Count & " pages.' );"
	end tell
end tell

What application are you scripting?

Some Adobe applications seem to support a with arguments option. You might try passing your arguments that way (they become available on the JavaScript side in a special array called arguments).

set jsCode to "frob( arguments[0], arguments[1] )"
tell application "Whatever"
	do script jsCode with arguments {"A", 3} -- on the JS side, arguments[0] == "A" and arguments[1] == 3
end tell

Great! Thanks, Mark67!

I think what I have confused is the usage of quotes (both ’ & "). I did try something similar before but received an error because I have added in extra quotes as below (after “This PDF has” and before “pages…”:-

I will try to figure them out later. Thanks again!