Skip to main content
Participant
June 5, 2008
Question

Auto-Align Layers using AS

  • June 5, 2008
  • 2 replies
  • 641 views
It is possible to Auto-Align Layers using AppleScript?
I cannot find the command in the Dictionary.
Otherwise the only solution is to call an action that call Auto-Align Layers.

Stefano
This topic has been closed for replies.

2 replies

Known Participant
June 6, 2008
Capste, an alternative to calling an action is to use script listener output code in your applescript and call this with do javascript. This way you need no external items. This should work as long as you have more than one layer selected when calling it. The six options should be self evident in the commented applescript line above the handler call.
----------------
tell application "Adobe Photoshop CS2"
activate
set Doc_Ref to the current document
tell Doc_Ref
-- AdLf, AdRg, AdCH, AdTp, AdBt, AdCV
my Align_Layers(Doc_Ref, "AdCH")
end tell
end tell

on Align_Layers(Doc_Ref, Align_Ref)
tell application "Adobe Photoshop CS2"
tell Doc_Ref
do javascript "Align_Layers(); function Align_Layers() {function cTID(s) { return app.charIDToTypeID(s); }; function sTID(s) { return app.stringIDToTypeID(s); }; var desc01 = new ActionDescriptor(); var ref01 = new ActionReference(); ref01.putEnumerated( cTID('Lyr '), cTID('Ordn'), cTID('Trgt') ); desc01.putReference( cTID('null'), ref01 ); desc01.putEnumerated( cTID('Usng'), cTID('ADSt'), cTID('" & Align_Ref & "') ); executeAction( cTID('Algn'), desc01, DialogModes.NO );};" show debugger on runtime error
end tell
end tell
end Align_Layers
----------------
Participating Frequently
June 5, 2008
You can't do it with vanilla AS. You can use System Events to choose one of the Align menu items after you link the layers. Plus the Action option isn't terrible.

If there's a way to align layers with Javascript, then you can insert the JS into your AS code.

Carl.