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

How to call javascript using applescript in InDesign cs2 Mac

New Here ,
Dec 08, 2007 Dec 08, 2007
Hi,
I need to integrate javascript with my apple script??? how to use it???please help me...i need it immediately..........
TOPICS
Scripting
1.3K
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
Valorous Hero ,
Dec 08, 2007 Dec 08, 2007
Hi subhaoviya,
Use do javascript command, below is an example.
Kasyan
------------------------------------
on manualUnsharp(amount1, radius1, threshold1, amount2, radius2, threshold2)
tell application "Adobe Photoshop CS2"
set myManualUnsharpScript to "
#target photoshop
app.bringToFront ();
var docRef = activeDocument;
makeUnsharpLayer() ;
manualUnsharp( arguments[0], arguments[1], arguments[2] );
manualUnsharp( arguments[3], arguments[4], arguments[5] );
function makeUnsharpLayer() {
if (docRef.layers.length > 1) {
for ( j = docRef.layers.length – 1; j > 0; j— ) {
if (docRef.layers.visible == false) {
docRef.layers.remove();
}
}
}
if (docRef.layers.length > 1) {
docRef.mergeVisibleLayers();
}
var myMergedLayer = docRef.activeLayer;
var mySharpLayer = docRef.activeLayer.duplicate(docRef.layers[0], ElementPlacement.PLACEBEFORE);
mySharpLayer.name = 'Unsharp Mask Layer';
docRef.activeLayer = mySharpLayer;
myMergedLayer.visible = false;
}
function manualUnsharp( amount, radius, threshold ) {
var id29 = charIDToTypeID( 'UnsM' );
var desc10 = new ActionDescriptor();
var id30 = charIDToTypeID( 'Amnt' );
var id31 = charIDToTypeID( '#Prc' );
desc10.putUnitDouble( id30, id31, amount );
var id32 = charIDToTypeID( 'Rds ' );
var id33 = charIDToTypeID( '#Pxl' );
desc10.putUnitDouble( id32, id33, radius );
var id34 = charIDToTypeID( 'Thsh' );
desc10.putInteger( id34,threshold );
try {
executeAction( id29, desc10, DialogModes.ALL );
}
catch (myError){
}
}"
do javascript myManualUnsharpScript with arguments {amount1, radius1, threshold1, amount2, radius2,
threshold2}
end tell
end manualUnsharp
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
New Here ,
Jan 29, 2008 Jan 29, 2008
Ok - that's exactly what i was looking for. But I'm curious how do you get deal with things in double quotes in the javascript ie: ref1.putName(PSClass.Layer, "B&W conversion HSL Adjustments"); Because applescript freeks out when I try to compile.

thanx.
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
Valorous Hero ,
Feb 03, 2008 Feb 03, 2008
Hi Andrew,
Here is an example for you – a snippet from my script:
---------------------------------------------------------------
global myBridgeLabel

-- function that runs on clicking the button in adobe script studio project
on clicked theObject
if name of theObject is "b1" then
set processName to "Started working"
set myBridgeLabel to "Red"
set myLabel to 1
else if name of theObject is "b2" then
set processName to "Started doing this"
set myBridgeLabel to "Green"
set myLabel to 2
else if name of theObject is "b3" then
set processName to "Started doing that"
set myBridgeLabel to "Yellow"
set myLabel to 3
else if name of theObject is "b4" then
set processName to "Finished doing this"
set myBridgeLabel to "Blue"
set myLabel to 4
else if name of theObject is "b5" then
set processName to "Finished doing that"
set myBridgeLabel to "Purple"
set myLabel to 5
end if

tell application "Adobe InDesign CS2"
set mydocument to active document
set myDocumentPath to full name of mydocument
set workerName to "Kasyan"

tell metadata preferences of mydocument
set theDate to current date
set myWeekday to weekday of theDate as string
set myDenNedeli to my convertWeekday(myWeekday)
set myRecord to (processName & " – " & workerName & " – ") & myDenNedeli & " " & text 1 thru -4 of time string of theDate & " \r"
set myHistory to get property namespace "http://ns.adobe.com/photoshop/1.0/" path "History"
set property namespace "http://ns.adobe.com/photoshop/1.0/" path "History" value myHistory & myRecord
end tell

set myJavaScript to "var myLabel =\"" & myBridgeLabel & "\"; app.activate(); var bt = new BridgeTalk; bt.target = \"bridge\"; myScript = 'app.displayDialogs = \"none\"; var t = new Thumbnail (File (\"" & myDocumentPath & "\")); var mdata = t.metadata; mdata.namespace = \"http://ns.adobe.com/xap/1.0/\"; mdata.Label = \"' + myLabel + '\";'; bt.body = myScript; bt.send();"

do script myJavaScript language javascript
---------------------------------------------------------------
In this javascript I use pares of single and double quotes.
The main java script – myJavaScript – (inside double quotes) contains another java script – myScript – (inside single quotes) which runs in Bridge via BridgeTalk.

I also put variables from AppleScript into JavaScript by using two pares of double quotes – the outside pare I escape with slashes:
…
set myBridgeLabel to "Red" -- a variable I defined in AppleScript
…
set myJavaScript to "var myLabel =\"" & myBridgeLabel & "\"; app.activate();
-- the contents of myBridgeLabel variable now becomes part of the JavaScript

Kasyan
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
New Here ,
Mar 24, 2008 Mar 24, 2008
Hi,

I'm wanting to execute a javascript from an applescript, but in an external file. Eg:

do script "[pathToFile]/myScript.jsx"

Is there a way to do this?

Thanks,
Burr
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
Valorous Hero ,
Mar 26, 2008 Mar 26, 2008
Hi Burr,

tell application "Adobe InDesign CS3"
set sScriptPath to "Macintosh HD:Applications:Adobe InDesign CS3:Scripts:Scripts Panel:YourJavaScript.jsx"
do script alias sScriptPath language javascript
end tell

Kasyan
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
New Here ,
Mar 27, 2008 Mar 27, 2008
Thanks!
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
New Here ,
Mar 27, 2008 Mar 27, 2008
Actually, I haven't got it working. I'm getting an error:

Adobe InDesign CS3 got an error: Expected: ;
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 ,
Mar 28, 2008 Mar 28, 2008
You have to pass a file reference not the filepath as a string. Do script will attempt to execute a string as JavaScript -- which is what causes the "Expected: ;" error.

Dave
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
Valorous Hero ,
Mar 28, 2008 Mar 28, 2008
LATEST
>Adobe InDesign CS3 got an error: Expected: ;

I tested my code again and made sure that it works. I suspect that the problem is caused by invalid path to the javascript file.

>You have to pass a file reference not the filepath as a string.

From ID scripting reference:
Method - do script
Parameter script alias or string

do script alias sScriptPath language javascript
do script sScriptPath language javascript

These both lines work, I tested.

Kasyan
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