do javascript using values from an Xcode application-newbie?

I am a newbie. In Photoshop CS, I’m using Applescript to rotate a layer around a point of “my” choosing rather than the fixed options of Middle, right corner, left corner… found in the Photoshop command.

I’m stumped as to how to do it in Applescript, so I invoked ScriptListener.js and it yielded this Javascript which works fine when called. My newbie problem is trying to take the text field values I manually enter into an applescript application created in Xcode and pass them to this bit of Javascript to replace the values (602.000000, 1509.104869, 10.000000, -0.000000, 101.000000, 101.000000, 0.300000).

for clarification:
(602.000000 is the x coordinate of the rotation point,
1509.104869 is the y coordinate of the rotation point,
10.000000 nudged/move the layer 10.000000 pixels to the right/left,
-0.000000 nudged/move the layer -0.000000 pixels to up/down,
101.000000 is the horizontal scale value,
101.000000 is the vertical scale value,
0.300000 is the rotation amount)

The bit of Javascript…

var id28 = charIDToTypeID( “Trnf” );
var desc6 = new ActionDescriptor();
var id29 = charIDToTypeID( “null” );
var ref3 = new ActionReference();
var id30 = charIDToTypeID( "Lyr " );
var id31 = charIDToTypeID( “Ordn” );
var id32 = charIDToTypeID( “Trgt” );
ref3.putEnumerated( id30, id31, id32 );
desc6.putReference( id29, ref3 );
var id33 = charIDToTypeID( “FTcs” );
var id34 = charIDToTypeID( “QCSt” );
var id35 = charIDToTypeID( “Qcsi” );
desc6.putEnumerated( id33, id34, id35 );
var id36 = charIDToTypeID( “Pstn” );
var desc7 = new ActionDescriptor();
var id37 = charIDToTypeID( “Hrzn” );
var id38 = charIDToTypeID( “#Pxl” );
desc7.putUnitDouble( id37, id38, 602.000000 );
var id39 = charIDToTypeID( “Vrtc” );
var id40 = charIDToTypeID( “#Pxl” );
desc7.putUnitDouble( id39, id40, 1509.104869 );
var id41 = charIDToTypeID( "Pnt " );
desc6.putObject( id36, id41, desc7 );
var id42 = charIDToTypeID( “Ofst” );
var desc8 = new ActionDescriptor();
var id43 = charIDToTypeID( “Hrzn” );
var id44 = charIDToTypeID( “#Pxl” );
desc8.putUnitDouble( id43, id44, 10.000000 );
var id45 = charIDToTypeID( “Vrtc” );
var id46 = charIDToTypeID( “#Pxl” );
desc8.putUnitDouble( id45, id46, -0.000000 );
var id47 = charIDToTypeID( “Ofst” );
desc6.putObject( id42, id47, desc8 );
var id48 = charIDToTypeID( “Wdth” );
var id49 = charIDToTypeID( “#Prc” );
desc6.putUnitDouble( id48, id49, 101.000000 );
var id50 = charIDToTypeID( “Hght” );
var id51 = charIDToTypeID( “#Prc” );
desc6.putUnitDouble( id50, id51, 101.000000 );
var id52 = charIDToTypeID( “Angl” );
var id53 = charIDToTypeID( “#Ang” );
desc6.putUnitDouble( id52, id53, 0.300000 );
var id54 = charIDToTypeID( “Lnkd” );
desc6.putBoolean( id54, true );
executeAction( id28, desc6, DialogModes.NO );

I could really use some help.
fermi

It’s just text. Assign your text to the contents of your text fields when you click a button and then swap that data into your JavaScript and tell Photoshop to execute the JavaScript:

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

The changes you suggested worked with a few tweeks. I learned a few things along the way, and have a few questions (like why does this work). Do you have a moment to look this through? (note:some of the variables are part of other scripts)

Here’s the applescript…

on clicked theObject
tell application “junk2”
set mtx to the contents of the text field “mtx” of window “Main”
set mty to the contents of the text field “mty” of window “Main”
set mbx to the contents of the text field “mbx” of window “Main”
set mby to the contents of the text field “mby” of window “Main”
set ttx to the contents of the text field “ttx01” of window “Main”
set tty to the contents of the text field “tty01” of window “Main”
set tbx to the contents of the text field “tbx01” of window “Main”
set tby to the contents of the text field “tby01” of window “Main”
set cside to hypot {(tbx - ttx), (tby - tty)}
set mside to hypot {(mbx - mtx), (mby - mty)}
set aside to (tbx - ttx)
set bside to (tby - tty)
set thepi to (pi)
set theasine to (asin (aside / cside))
set thedegrees to (((theasine / (thepi / 180)) / (-4)))
set the contents of the text field “rotate01” of window “Main” to thedegrees
set the contents of the text field “scale01” of window “Main” to ((mside * 100) / cside)
set the contents of the text field “nudgelr01” of window “Main” to (mbx - tbx) as real
set the contents of the text field “nudgeud01” of window “main” to (mby - tby) as real

set scalex to contents of text field "scale01" of window "Main"
set scaley to contents of text field "scale01" of window "Main"
set rotatePtx to contents of text field "mbx" of window "Main" as real
set rotatePty to contents of text field "mby" of window "Main" as real
set nudgex to contents of text field "nudgelr01" of window "Main"
set nudgey to contents of text field "nudgeud01" of window "Main"
set therotate to contents of text field "rotate01" of window "Main"

end tell

– here I had to do a few things.
– 1. to embed the javascript vs sending Photoshop to go get it, it was
– necessary to put the in front of each " to permit the “containerization”
– of the script. I didn’t notice you had done that at first.
– 2. the javascript “rotatescript” did not understand the "‘set’ business above, but I
– found it would accept an array. See the "with argument {scalex, scaley,…}
– at the very bottom of this post.
– 3. now here is where I don’t quite get it, or why this works… immediately below
– this sentence is the "set rotatescript to "{ ( scalex = arguments[0].toString() ),…
– stuff. The error I kept getting was "#1224 error “rotatePtx is undefined”, so I
– cobbled together this arguments statement. It works, but it’s not pretty. What
– should I be seeing here that I’m not?

set rotatescript to "{ ( scalex = arguments[0].toString() ), ( scaley = arguments[1].toString() ), ( rotatePtx = arguments[2].toString() ), ( rotatePty = arguments[3].toString() ), ( nudgex = arguments[4].toString() ), ( nudgey = arguments[5].toString() ), ( therotate = arguments[6].toString() ) };
var id3 = charIDToTypeID( “slct” );
var desc2 = new ActionDescriptor();
var id4 = charIDToTypeID( “null” );
var ref1 = new ActionReference();
var id5 = charIDToTypeID( "Lyr " );
ref1.putName( id5, “001.jpg”);
desc2.putReference( id4, ref1 );
executeAction( id3, desc2, DialogModes.NO );
var id6 = charIDToTypeID( “Trnf” );
var desc3 = new ActionDescriptor();
var id7 = charIDToTypeID( “null” );
var ref2 = new ActionReference();
var id8 = charIDToTypeID( "Lyr " );
var id9 = charIDToTypeID( “Ordn” );
var id10 = charIDToTypeID( “Trgt” );
ref2.putEnumerated( id8, id9, id10 );
desc3.putReference( id7, ref2 );
var id11 = charIDToTypeID( “FTcs” );
var id12 = charIDToTypeID( “QCSt” );
var id13 = charIDToTypeID( “Qcsi” );
desc3.putEnumerated( id11, id12, id13 );
var id14 = charIDToTypeID( “Pstn” );
var desc4 = new ActionDescriptor();
var id15 = charIDToTypeID( “Hrzn” );
var id16 = charIDToTypeID( “#Pxl” );
desc4.putUnitDouble( id15, id16, rotatePtx );
var id17 = charIDToTypeID( “Vrtc” );
var id18 = charIDToTypeID( “#Pxl” );
desc4.putUnitDouble( id17, id18, rotatePty );
var id19 = charIDToTypeID( "Pnt " );
desc3.putObject( id14, id19, desc4 );
var id20 = charIDToTypeID( “Ofst” );
var desc5 = new ActionDescriptor();
var id21 = charIDToTypeID( “Hrzn” );
var id22 = charIDToTypeID( “#Pxl” );
desc5.putUnitDouble( id21, id22, nudgex );
var id23 = charIDToTypeID( “Vrtc” );
var id24 = charIDToTypeID( “#Pxl” );
desc5.putUnitDouble( id23, id24, nudgey );
var id25 = charIDToTypeID( “Ofst” );
desc3.putObject( id20, id25, desc5 );
var id26 = charIDToTypeID( “Wdth” );
var id27 = charIDToTypeID( “#Prc” );
desc3.putUnitDouble( id26, id27, scalex );
var id28 = charIDToTypeID( “Hght” );
var id29 = charIDToTypeID( “#Prc” );
desc3.putUnitDouble( id28, id29, scaley );
var id30 = charIDToTypeID( “Angl” );
var id31 = charIDToTypeID( “#Ang” );
desc3.putUnitDouble( id30, id31, therotate );
var id32 = charIDToTypeID( “Lnkd” );
desc3.putBoolean( id32, true );
executeAction( id6, desc3, DialogModes.NO );
"
tell application “Adobe Photoshop CS”
– activate
set docref to current document
do javascript rotatescript with arguments {scalex, scaley, rotatePtx, rotatePty, nudgex, nudgey, therotate} – to call the script direct here is an example (alias “OSX:Applications:Adobe Photoshop CS:Presets:Scripts:rotatescript.js”)
end tell
end clicked :rolleyes: