mirror of
https://github.com/sbrow/ps.git
synced 2025-12-29 18:47:38 -05:00
Updates, Improvements, and Fixes
* Moved scripts / runner to separate package
allows future replacement with PS Plugin.
* Fixed issues with Refresh and removed "layer" function.
* Added github documentation via godocdown.
* Reduced number of calls to Panic.
* Updated Tests
* Updated documentation.
* Fixed warnings.
* .gitignore now ignores .test and .out files.
This commit is contained in:
BIN
runner/debug.test
Normal file
BIN
runner/debug.test
Normal file
Binary file not shown.
65
runner/runner.go
Normal file
65
runner/runner.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package runner
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Windows is the runner for Visual Basic Scripts.
|
||||
var Windows = Runner{
|
||||
Cmd: "cscript.exe",
|
||||
Args: []string{"/nologo"},
|
||||
Ext: ".vbs",
|
||||
}
|
||||
|
||||
// pkgpath is the path to this package.
|
||||
var pkgpath string
|
||||
|
||||
// std is the Standard Runner.
|
||||
var std Runner
|
||||
|
||||
func init() {
|
||||
_, file, _, _ := runtime.Caller(0)
|
||||
pkgpath = filepath.Dir(file)
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
std = Windows
|
||||
}
|
||||
}
|
||||
|
||||
// Runner runs script files to communicate between the OS/Photoshop and the Go code.
|
||||
type Runner struct {
|
||||
Cmd string // The name of the command to run
|
||||
Args []string // The arguments to pass to the command.
|
||||
Ext string // The file extension to use for these commands.
|
||||
}
|
||||
|
||||
// Run runs the standard runner with the given values.
|
||||
func Run(name string, args ...string) ([]byte, error) {
|
||||
var out, errs bytes.Buffer
|
||||
cmd := exec.Command(std.Cmd, parseArgs(name, args...)...)
|
||||
cmd.Stdout, cmd.Stderr = &out, &errs
|
||||
if err := cmd.Run(); err != nil || len(errs.Bytes()) != 0 {
|
||||
return out.Bytes(), errors.New(errs.String())
|
||||
}
|
||||
return out.Bytes(), nil
|
||||
}
|
||||
|
||||
// parseArgs parses the given args into the correct syntax.
|
||||
func parseArgs(name string, args ...string) []string {
|
||||
if !strings.HasSuffix(name, std.Ext) {
|
||||
name += std.Ext
|
||||
}
|
||||
newArgs := append(std.Args, filepath.Join(pkgpath, "scripts", name))
|
||||
if strings.Contains(name, "dojs") {
|
||||
newArgs = append(newArgs, args[0], fmt.Sprint(strings.Join(args[1:], ",,")))
|
||||
} else {
|
||||
newArgs = append(newArgs, args...)
|
||||
}
|
||||
return newArgs
|
||||
}
|
||||
55
runner/runner_test.go
Normal file
55
runner/runner_test.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package runner
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var scripts string
|
||||
|
||||
func init() {
|
||||
var ok bool
|
||||
_, file, _, ok := runtime.Caller(0)
|
||||
if !ok {
|
||||
log.Panic("package path not found")
|
||||
}
|
||||
pkgpath = filepath.Dir(file)
|
||||
scripts = filepath.Join(pkgpath, "scripts")
|
||||
}
|
||||
func TestRun(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
args []string
|
||||
want []byte
|
||||
wantErr bool
|
||||
}{
|
||||
{"dojs", []string{filepath.Join(scripts, "test.jsx"), filepath.Join(scripts, "test.txt"), "arg1", "arg2"},
|
||||
[]byte(filepath.Join(scripts, "test.txt") + "\r\narg1\r\narg2\r\n"), false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, err := Run(tt.name, tt.args...)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("Run() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
f, err := os.Open(tt.args[1])
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
got, err := ioutil.ReadAll(f)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if string(got) != string(tt.want) {
|
||||
t.Errorf("Run() = \n%v, want \n%v", string(got), string(tt.want))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
12
runner/scripts/PsIsOpen.vbs
Normal file
12
runner/scripts/PsIsOpen.vbs
Normal file
@@ -0,0 +1,12 @@
|
||||
Function IsProcessRunning( strComputer, strProcess )
|
||||
Dim Process, strObject
|
||||
IsProcessRunning = False
|
||||
strObject = "winmgmts://" & strComputer
|
||||
For Each Process in GetObject( strObject ).InstancesOf( "win32_process" )
|
||||
If UCase( Process.name ) = UCase( strProcess ) Then
|
||||
IsProcessRunning = True
|
||||
Exit Function
|
||||
End If
|
||||
Next
|
||||
End Function
|
||||
wScript.Echo IsProcessRunning(".", "Photoshop.exe")
|
||||
10
runner/scripts/action.vbs
Normal file
10
runner/scripts/action.vbs
Normal file
@@ -0,0 +1,10 @@
|
||||
set appRef = CreateObject("Photoshop.Application")
|
||||
' No dialogs'
|
||||
dlgMode = 3
|
||||
|
||||
set desc = CreateObject( "Photoshop.ActionDescriptor" )
|
||||
set ref = CreateObject( "Photoshop.ActionReference" )
|
||||
Call ref.PutName(appRef.CharIDToTypeID("Actn"), wScript.Arguments(1))
|
||||
Call ref.PutName(appRef.CharIDToTypeID("ASet"), wScript.Arguments(0))
|
||||
Call desc.PutReference(appRef.CharIDToTypeID("null"), ref)
|
||||
Call appRef.ExecuteAction(appRef.CharIDToTypeID("Ply "), desc, dlgMode)
|
||||
2
runner/scripts/activeDocName.jsx
Normal file
2
runner/scripts/activeDocName.jsx
Normal file
@@ -0,0 +1,2 @@
|
||||
#include lib.js
|
||||
var stdout = newFile(arguments[0]);stdout.writeln(app.activeDocument.name);stdout.close();
|
||||
15
runner/scripts/applyDataset.jsx
Normal file
15
runner/scripts/applyDataset.jsx
Normal file
@@ -0,0 +1,15 @@
|
||||
var saveFile = File(arguments[0]);
|
||||
if(saveFile.exists)
|
||||
saveFile.remove();
|
||||
var idAply = charIDToTypeID("Aply");
|
||||
var desc1 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref1 = new ActionReference();
|
||||
var iddataSetClass = stringIDToTypeID("dataSetClass");
|
||||
ref1.putName(iddataSetClass, arguments[1]);
|
||||
desc1.putReference(idnull, ref1);
|
||||
executeAction(idAply, desc1, DialogModes.NO);
|
||||
saveFile.encoding = "UTF8";
|
||||
saveFile.open("e", "TEXT", "????");
|
||||
saveFile.writeln("done!");
|
||||
saveFile.close();
|
||||
3
runner/scripts/close.vbs
Normal file
3
runner/scripts/close.vbs
Normal file
@@ -0,0 +1,3 @@
|
||||
set App = CreateObject("Photoshop.Application")
|
||||
set Doc = App.activeDocument
|
||||
Doc.Close(CInt(wScript.Arguments(0)))
|
||||
76
runner/scripts/colorLayer.vbs
Normal file
76
runner/scripts/colorLayer.vbs
Normal file
@@ -0,0 +1,76 @@
|
||||
DIM objApp
|
||||
SET objApp = CreateObject("Photoshop.Application")
|
||||
DIM dialogMode
|
||||
dialogMode = 3
|
||||
DIM idsetd
|
||||
idsetd = objApp.CharIDToTypeID("setd")
|
||||
DIM desc134
|
||||
SET desc134 = CreateObject("Photoshop.ActionDescriptor")
|
||||
DIM idnull
|
||||
idnull = objApp.CharIDToTypeID("null")
|
||||
DIM ref44
|
||||
SET ref44 = CreateObject("Photoshop.ActionReference")
|
||||
DIM idPrpr
|
||||
idPrpr = objApp.CharIDToTypeID("Prpr")
|
||||
DIM idLefx
|
||||
idLefx = objApp.CharIDToTypeID("Lefx")
|
||||
Call ref44.PutProperty(idPrpr, idLefx)
|
||||
DIM idLyr
|
||||
idLyr = objApp.CharIDToTypeID("Lyr ")
|
||||
DIM idOrdn
|
||||
idOrdn = objApp.CharIDToTypeID("Ordn")
|
||||
DIM idTrgt
|
||||
idTrgt = objApp.CharIDToTypeID("Trgt")
|
||||
Call ref44.PutEnumerated(idLyr, idOrdn, idTrgt)
|
||||
Call desc134.PutReference(idnull, ref44)
|
||||
DIM idT
|
||||
idT = objApp.CharIDToTypeID("T ")
|
||||
DIM desc135
|
||||
SET desc135 = CreateObject("Photoshop.ActionDescriptor")
|
||||
DIM idScl
|
||||
idScl = objApp.CharIDToTypeID("Scl ")
|
||||
DIM idPrc
|
||||
idPrc = objApp.CharIDToTypeID("#Prc")
|
||||
Call desc135.PutUnitDouble(idScl, idPrc, 416.666667)
|
||||
DIM idSoFi
|
||||
idSoFi = objApp.CharIDToTypeID("SoFi")
|
||||
DIM desc136
|
||||
SET desc136 = CreateObject("Photoshop.ActionDescriptor")
|
||||
DIM idenab
|
||||
idenab = objApp.CharIDToTypeID("enab")
|
||||
Call desc136.PutBoolean(idenab, True)
|
||||
DIM idMd
|
||||
idMd = objApp.CharIDToTypeID("Md ")
|
||||
DIM idBlnM
|
||||
idBlnM = objApp.CharIDToTypeID("BlnM")
|
||||
DIM idNrml
|
||||
idNrml = objApp.CharIDToTypeID("Nrml")
|
||||
Call desc136.PutEnumerated(idMd, idBlnM, idNrml)
|
||||
DIM idOpct
|
||||
idOpct = objApp.CharIDToTypeID("Opct")
|
||||
idPrc = objApp.CharIDToTypeID("#Prc")
|
||||
Call desc136.PutUnitDouble(idOpct, idPrc, 100.000000)
|
||||
DIM idClr
|
||||
idClr = objApp.CharIDToTypeID("Clr ")
|
||||
DIM desc137
|
||||
SET desc137 = CreateObject("Photoshop.ActionDescriptor")
|
||||
DIM idRd
|
||||
idRd = objApp.CharIDToTypeID("Rd ")
|
||||
Call desc137.PutDouble(idRd, CInt(wScript.Arguments(0)))
|
||||
' Call desc137.PutDouble(idRd, 255)
|
||||
DIM idGrn
|
||||
idGrn = objApp.CharIDToTypeID("Grn ")
|
||||
Call desc137.PutDouble(idGrn, Cint(wScript.Arguments(1)))
|
||||
' Call desc137.PutDouble(idGrn, 255)
|
||||
DIM idBl
|
||||
idBl = objApp.CharIDToTypeID("Bl ")
|
||||
Call desc137.PutDouble(idBl, CInt(wScript.Arguments(2)))
|
||||
' Call desc137.PutDouble(idBl, 255)
|
||||
DIM idRGBC
|
||||
idRGBC = objApp.CharIDToTypeID("RGBC")
|
||||
Call desc136.PutObject(idClr, idRGBC, desc137)
|
||||
idSoFi = objApp.CharIDToTypeID("SoFi")
|
||||
Call desc135.PutObject(idSoFi, idSoFi, desc136)
|
||||
idLefx = objApp.CharIDToTypeID("Lefx")
|
||||
Call desc134.PutObject(idT, idLefx, desc135)
|
||||
Call objApp.ExecuteAction(idsetd, desc134, dialogMode)
|
||||
120
runner/scripts/colorStroke.vbs
Normal file
120
runner/scripts/colorStroke.vbs
Normal file
@@ -0,0 +1,120 @@
|
||||
DIM objApp
|
||||
SET objApp = CreateObject("Photoshop.Application")
|
||||
REM Use dialog mode 3 for show no dialogs
|
||||
DIM dialogMode
|
||||
dialogMode = 3
|
||||
DIM idsetd
|
||||
idsetd = objApp.CharIDToTypeID("setd")
|
||||
DIM desc2
|
||||
SET desc2 = CreateObject("Photoshop.ActionDescriptor")
|
||||
DIM idnull
|
||||
idnull = objApp.CharIDToTypeID("null")
|
||||
DIM ref2
|
||||
SET ref2 = CreateObject("Photoshop.ActionReference")
|
||||
DIM idPrpr
|
||||
idPrpr = objApp.CharIDToTypeID("Prpr")
|
||||
DIM idLefx
|
||||
idLefx = objApp.CharIDToTypeID("Lefx")
|
||||
Call ref2.PutProperty(idPrpr, idLefx)
|
||||
DIM idLyr
|
||||
idLyr = objApp.CharIDToTypeID("Lyr ")
|
||||
DIM idOrdn
|
||||
idOrdn = objApp.CharIDToTypeID("Ordn")
|
||||
DIM idTrgt
|
||||
idTrgt = objApp.CharIDToTypeID("Trgt")
|
||||
Call ref2.PutEnumerated(idLyr, idOrdn, idTrgt)
|
||||
Call desc2.PutReference(idnull, ref2)
|
||||
DIM idT
|
||||
idT = objApp.CharIDToTypeID("T ")
|
||||
DIM desc3
|
||||
SET desc3 = CreateObject("Photoshop.ActionDescriptor")
|
||||
DIM idScl
|
||||
idScl = objApp.CharIDToTypeID("Scl ")
|
||||
DIM idPrc
|
||||
idPrc = objApp.CharIDToTypeID("#Prc")
|
||||
Call desc3.PutUnitDouble(idScl, idPrc, 416.666667)
|
||||
DIM idSoFi
|
||||
idSoFi = objApp.CharIDToTypeID("SoFi")
|
||||
DIM desc4
|
||||
SET desc4 = CreateObject("Photoshop.ActionDescriptor")
|
||||
DIM idenab
|
||||
idenab = objApp.CharIDToTypeID("enab")
|
||||
Call desc4.PutBoolean(idenab, True)
|
||||
DIM idMd
|
||||
idMd = objApp.CharIDToTypeID("Md ")
|
||||
DIM idBlnM
|
||||
idBlnM = objApp.CharIDToTypeID("BlnM")
|
||||
DIM idNrml
|
||||
idNrml = objApp.CharIDToTypeID("Nrml")
|
||||
Call desc4.PutEnumerated(idMd, idBlnM, idNrml)
|
||||
DIM idOpct
|
||||
idOpct = objApp.CharIDToTypeID("Opct")
|
||||
idPrc = objApp.CharIDToTypeID("#Prc")
|
||||
Call desc4.PutUnitDouble(idOpct, idPrc, 100.000000)
|
||||
DIM idClr
|
||||
idClr = objApp.CharIDToTypeID("Clr ")
|
||||
DIM desc5
|
||||
SET desc5 = CreateObject("Photoshop.ActionDescriptor")
|
||||
DIM idRd
|
||||
idRd = objApp.CharIDToTypeID("Rd ")
|
||||
Call desc5.PutDouble(idRd, CInt(wScript.Arguments(0)))
|
||||
DIM idGrn
|
||||
idGrn = objApp.CharIDToTypeID("Grn ")
|
||||
Call desc5.PutDouble(idGrn,CInt(wScript.Arguments(1)))
|
||||
DIM idBl
|
||||
idBl = objApp.CharIDToTypeID("Bl ")
|
||||
Call desc5.PutDouble(idBl, CInt(wScript.Arguments(2)))
|
||||
DIM idRGBC
|
||||
idRGBC = objApp.CharIDToTypeID("RGBC")
|
||||
Call desc4.PutObject(idClr, idRGBC, desc5)
|
||||
idSoFi = objApp.CharIDToTypeID("SoFi")
|
||||
Call desc3.PutObject(idSoFi, idSoFi, desc4)
|
||||
DIM idFrFX
|
||||
idFrFX = objApp.CharIDToTypeID("FrFX")
|
||||
DIM desc6
|
||||
SET desc6 = CreateObject("Photoshop.ActionDescriptor")
|
||||
idenab = objApp.CharIDToTypeID("enab")
|
||||
Call desc6.PutBoolean(idenab, True)
|
||||
DIM idStyl
|
||||
idStyl = objApp.CharIDToTypeID("Styl")
|
||||
DIM idFStl
|
||||
idFStl = objApp.CharIDToTypeID("FStl")
|
||||
DIM idOutF
|
||||
idOutF = objApp.CharIDToTypeID("OutF")
|
||||
Call desc6.PutEnumerated(idStyl, idFStl, idOutF)
|
||||
DIM idPntT
|
||||
idPntT = objApp.CharIDToTypeID("PntT")
|
||||
DIM idFrFl
|
||||
idFrFl = objApp.CharIDToTypeID("FrFl")
|
||||
DIM idSClr
|
||||
idSClr = objApp.CharIDToTypeID("SClr")
|
||||
Call desc6.PutEnumerated(idPntT, idFrFl, idSClr)
|
||||
idMd = objApp.CharIDToTypeID("Md ")
|
||||
idBlnM = objApp.CharIDToTypeID("BlnM")
|
||||
idNrml = objApp.CharIDToTypeID("Nrml")
|
||||
Call desc6.PutEnumerated(idMd, idBlnM, idNrml)
|
||||
idOpct = objApp.CharIDToTypeID("Opct")
|
||||
idPrc = objApp.CharIDToTypeID("#Prc")
|
||||
Call desc6.PutUnitDouble(idOpct, idPrc, 100.000000)
|
||||
DIM idSz
|
||||
idSz = objApp.CharIDToTypeID("Sz ")
|
||||
DIM idPxl
|
||||
idPxl = objApp.CharIDToTypeID("#Pxl")
|
||||
Call desc6.PutUnitDouble(idSz, idPxl, CLng(wScript.Arguments(3)))
|
||||
idClr = objApp.CharIDToTypeID("Clr ")
|
||||
DIM desc7
|
||||
SET desc7 = CreateObject("Photoshop.ActionDescriptor")
|
||||
idRd = objApp.CharIDToTypeID("Rd ")
|
||||
Call desc7.PutDouble(idRd, CInt(wScript.Arguments(4)))
|
||||
idGrn = objApp.CharIDToTypeID("Grn ")
|
||||
Call desc7.PutDouble(idGrn, CInt(wScript.Arguments(5)))
|
||||
idBl = objApp.CharIDToTypeID("Bl ")
|
||||
Call desc7.PutDouble(idBl, CInt(wScript.Arguments(6)))
|
||||
idRGBC = objApp.CharIDToTypeID("RGBC")
|
||||
Call desc6.PutObject(idClr, idRGBC, desc7)
|
||||
idFrFX = objApp.CharIDToTypeID("FrFX")
|
||||
Call desc3.PutObject(idFrFX, idFrFX, desc6)
|
||||
idLefx = objApp.CharIDToTypeID("Lefx")
|
||||
Call desc2.PutObject(idT, idLefx, desc3)
|
||||
Call objApp.ExecuteAction(idsetd, desc2, dialogMode)
|
||||
|
||||
4
runner/scripts/compilejs.jsx
Normal file
4
runner/scripts/compilejs.jsx
Normal file
@@ -0,0 +1,4 @@
|
||||
#include lib.js
|
||||
var stdout = newFile(arguments[0])
|
||||
eval(arguments[1]);
|
||||
stdout.close()
|
||||
15
runner/scripts/dojs.vbs
Normal file
15
runner/scripts/dojs.vbs
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
Dim appRef
|
||||
Set appRef = CreateObject("Photoshop.Application")
|
||||
if wScript.Arguments.Count = 0 then
|
||||
wScript.Echo "Missing parameters"
|
||||
else
|
||||
' wScript.Echo wScript.Arguments(0)
|
||||
' wScript.Echo wScript.Arguments(1)
|
||||
path = wScript.Arguments(0)
|
||||
args = wScript.Arguments(1)
|
||||
error = appRef.DoJavaScriptFile(path, Split(args, ",,"))
|
||||
if Not error = "true" and Not error = "[ActionDescriptor]" and Not error = "undefined" Then
|
||||
Err.raise 1, "dojs.vbs", error
|
||||
end if
|
||||
end if
|
||||
54
runner/scripts/fmtText.jsx
Normal file
54
runner/scripts/fmtText.jsx
Normal file
@@ -0,0 +1,54 @@
|
||||
if(app.activeDocument.activeLayer.kind == LayerKind.TEXT){
|
||||
var activeLayer = app.activeDocument.activeLayer;
|
||||
if(activeLayer.kind == LayerKind.TEXT){
|
||||
var start = parseInt(arguments[1]);
|
||||
var end = parseInt(arguments[2]);
|
||||
var fontName = arguments[3];
|
||||
var fontStyle = arguments[4];
|
||||
var fontSize = activeLayer.textItem.size;
|
||||
var colorArray = [0, 0, 0];
|
||||
if((activeLayer.textItem.contents != "")&&(start >= 0)&&(end <= activeLayer.textItem.contents.length)){
|
||||
var idsetd = app.charIDToTypeID( "setd" );
|
||||
var action = new ActionDescriptor();
|
||||
var idnull = app.charIDToTypeID( "null" );
|
||||
var reference = new ActionReference();
|
||||
var idTxLr = app.charIDToTypeID( "TxLr" );
|
||||
var idOrdn = app.charIDToTypeID( "Ordn" );
|
||||
var idTrgt = app.charIDToTypeID( "Trgt" );
|
||||
reference.putEnumerated( idTxLr, idOrdn, idTrgt );
|
||||
action.putReference( idnull, reference );
|
||||
var idT = app.charIDToTypeID( "T " );
|
||||
var textAction = new ActionDescriptor();
|
||||
var idTxtt = app.charIDToTypeID( "Txtt" );
|
||||
var actionList = new ActionList();
|
||||
var textRange = new ActionDescriptor();
|
||||
var idFrom = app.charIDToTypeID( "From" );
|
||||
textRange.putInteger( idFrom, start );
|
||||
textRange.putInteger( idT, end );
|
||||
var idTxtS = app.charIDToTypeID( "TxtS" );
|
||||
var formatting = new ActionDescriptor();
|
||||
var idFntN = app.charIDToTypeID( "FntN" );
|
||||
formatting.putString( idFntN, fontName );
|
||||
var idFntS = app.charIDToTypeID( "FntS" );
|
||||
formatting.putString( idFntS, fontStyle );
|
||||
var idSz = app.charIDToTypeID( "Sz " );
|
||||
var idPnt = app.charIDToTypeID( "#Pnt" );
|
||||
formatting.putUnitDouble( idSz, idPnt, fontSize );
|
||||
var idClr = app.charIDToTypeID( "Clr " );
|
||||
var colorAction = new ActionDescriptor();
|
||||
var idRd = app.charIDToTypeID( "Rd " );
|
||||
colorAction.putDouble( idRd, colorArray[0] );
|
||||
var idGrn = app.charIDToTypeID( "Grn " );
|
||||
colorAction.putDouble( idGrn, colorArray[1]);
|
||||
var idBl = app.charIDToTypeID( "Bl " );
|
||||
colorAction.putDouble( idBl, colorArray[2] );
|
||||
var idRGBC = app.charIDToTypeID( "RGBC" );
|
||||
formatting.putObject( idClr, idRGBC, colorAction );
|
||||
textRange.putObject( idTxtS, idTxtS, formatting );
|
||||
actionList.putObject( idTxtt, textRange );
|
||||
textAction.putList( idTxtt, actionList );
|
||||
action.putObject( idT, idTxLr, textAction );
|
||||
app.executeAction( idsetd, action, DialogModes.NO );
|
||||
}
|
||||
}
|
||||
}
|
||||
22
runner/scripts/getActiveDoc.jsx
Normal file
22
runner/scripts/getActiveDoc.jsx
Normal file
@@ -0,0 +1,22 @@
|
||||
#include lib.js
|
||||
var stdout = newFile(arguments[0]);
|
||||
var doc = app.activeDocument;
|
||||
stdout.writeln(('{"Name": "'+doc.name+'", "Height":'+doc.height+
|
||||
', "Width":'+doc.width+', "ArtLayers": [').replace(/ px/g, ""));
|
||||
|
||||
stdout.writeln(layers(doc.artLayers))
|
||||
stdout.writeln('], "LayerSets": [');
|
||||
function lyrSets(sets, nm) {
|
||||
if (typeof sets === 'undefined')
|
||||
return;
|
||||
for (var i = 0; i < sets.length; i++) {
|
||||
var set = sets[i];
|
||||
var name = nm + set.name + "/";
|
||||
stdout.write('{"Name": "' + set.name + '", "Visible":'+ set.visible +'}');
|
||||
if (i+1 != sets.length)
|
||||
stdout.write(',');
|
||||
}
|
||||
}
|
||||
lyrSets(doc.layerSets)
|
||||
stdout.write(']}');
|
||||
stdout.close();
|
||||
6
runner/scripts/getLayer.jsx
Normal file
6
runner/scripts/getLayer.jsx
Normal file
@@ -0,0 +1,6 @@
|
||||
#include lib.js
|
||||
app.displayDialogs=DialogModes.NO
|
||||
var stdout = newFile(arguments[0]);
|
||||
var lyr = eval(arguments[1]);
|
||||
var lyrs = [lyr];
|
||||
stdout.writeln(layers(lyrs))
|
||||
21
runner/scripts/getLayerSet.jsx
Normal file
21
runner/scripts/getLayerSet.jsx
Normal file
@@ -0,0 +1,21 @@
|
||||
#include lib.js
|
||||
var stdout = newFile(arguments[0]);
|
||||
var set = eval(arguments[1]);
|
||||
stdout.writeln('{"Name": "'+set.name+'", "Visible": '+ set.visible +', "ArtLayers":[');
|
||||
stdout.flush();
|
||||
var str = layers(set.artLayers);
|
||||
str = str.replace(/\r/g, "\\r");
|
||||
stdout.writeln(str);
|
||||
stdout.writeln("]");
|
||||
stdout.write(', "LayerSets": [')
|
||||
for (var i = 0; i < set.layerSets.length; i++) {
|
||||
var s = set.layerSets[i];
|
||||
stdout.write('{"Name":"' + s.name + '", "Visible": ' + s.visible + '}');
|
||||
if (i < set.layerSets.length - 1)
|
||||
stdout.writeln(",");
|
||||
stdout.flush()
|
||||
}
|
||||
stdout.writeln(']')
|
||||
stdout.write(', "Bounds": [[],[]]');
|
||||
stdout.write("}");
|
||||
stdout.close();
|
||||
2
runner/scripts/isVisible.jsx
Normal file
2
runner/scripts/isVisible.jsx
Normal file
@@ -0,0 +1,2 @@
|
||||
#include lib.js
|
||||
var stdout = newFile(arguments[0]);stdout.writeln(eval(arguments[1]).visible);stdout.close();
|
||||
11
runner/scripts/layerSetBounds.jsx
Normal file
11
runner/scripts/layerSetBounds.jsx
Normal file
@@ -0,0 +1,11 @@
|
||||
#include lib.js
|
||||
var stdout = newFile(arguments[0]);
|
||||
var set = eval(arguments[1]);
|
||||
app.activeDocument.activeLayer=set;
|
||||
set.merge();
|
||||
set=eval(arguments[2]);
|
||||
stdout.write(('[[' + set.bounds[0] + ',' +
|
||||
set.bounds[1] + '],[' + set.bounds[2] + ',' +
|
||||
set.bounds[3] + ']]').replace(/ px/g, ""));
|
||||
Undo();
|
||||
stdout.close();
|
||||
122
runner/scripts/lib.js
Normal file
122
runner/scripts/lib.js
Normal file
@@ -0,0 +1,122 @@
|
||||
// Opens and returns a file, overwriting new data.
|
||||
function newFile(path) {
|
||||
var f = File(path)
|
||||
f.encoding = "UTF8"
|
||||
f.open("w")
|
||||
return f
|
||||
}
|
||||
|
||||
File.prototype.flush = function() {
|
||||
this.close()
|
||||
this.open("a")
|
||||
};
|
||||
function flush(file) {
|
||||
file.close()
|
||||
file.open("a")
|
||||
}
|
||||
|
||||
|
||||
// Prints an error message.
|
||||
function err(e) {
|
||||
return 'ERROR: ' + e.message + ' at ' + e.fileName + ':' + e.line;
|
||||
}
|
||||
|
||||
function bounds(lyr) {
|
||||
return ('"Bounds": [[' + lyr.bounds[0] + ',' +
|
||||
lyr.bounds[1] + '],[' + lyr.bounds[2] + ',' +
|
||||
lyr.bounds[3] + ']]').replace(/ px/g, "");
|
||||
}
|
||||
|
||||
function Undo() {
|
||||
var desc = new ActionDescriptor();
|
||||
var ref = new ActionReference();
|
||||
ref.putEnumerated( charIDToTypeID( "HstS" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Prvs" ));
|
||||
desc.putReference(charIDToTypeID( "null" ), ref);
|
||||
executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
|
||||
}
|
||||
|
||||
/**
|
||||
* The setFormatting function sets the font, font style, point size, and RGB color of specified
|
||||
* characters in a Photoshop text layer.
|
||||
*
|
||||
* @param start (int) the index of the insertion point *before* the character you want.,
|
||||
* @param end (int) the index of the insertion point following the character.
|
||||
* @param fontName is a string for the font name.
|
||||
* @param fontStyle is a string for the font style.
|
||||
* @param fontSize (Number) the point size of the text.
|
||||
* @param colorArray (Array) is the RGB color to be applied to the text.
|
||||
*/
|
||||
function setFormatting(start, end, fontName, fontStyle, fontSize, colorArray) {
|
||||
if(app.activeDocument.activeLayer.kind == LayerKind.TEXT){
|
||||
var activeLayer = app.activeDocument.activeLayer;
|
||||
fontSize = activeLayer.textItem.size;
|
||||
colorArray = [0, 0, 0];
|
||||
if(activeLayer.kind == LayerKind.TEXT){
|
||||
if((activeLayer.textItem.contents != "")&&(start >= 0)&&(end <= activeLayer.textItem.contents.length)){
|
||||
var idsetd = app.charIDToTypeID( "setd" );
|
||||
var action = new ActionDescriptor();
|
||||
var idnull = app.charIDToTypeID( "null" );
|
||||
var reference = new ActionReference();
|
||||
var idTxLr = app.charIDToTypeID( "TxLr" );
|
||||
var idOrdn = app.charIDToTypeID( "Ordn" );
|
||||
var idTrgt = app.charIDToTypeID( "Trgt" );
|
||||
reference.putEnumerated( idTxLr, idOrdn, idTrgt );
|
||||
action.putReference( idnull, reference );
|
||||
var idT = app.charIDToTypeID( "T " );
|
||||
var textAction = new ActionDescriptor();
|
||||
var idTxtt = app.charIDToTypeID( "Txtt" );
|
||||
var actionList = new ActionList();
|
||||
var textRange = new ActionDescriptor();
|
||||
var idFrom = app.charIDToTypeID( "From" );
|
||||
textRange.putInteger( idFrom, start );
|
||||
textRange.putInteger( idT, end );
|
||||
var idTxtS = app.charIDToTypeID( "TxtS" );
|
||||
var formatting = new ActionDescriptor();
|
||||
var idFntN = app.charIDToTypeID( "FntN" );
|
||||
formatting.putString( idFntN, fontName );
|
||||
var idFntS = app.charIDToTypeID( "FntS" );
|
||||
formatting.putString( idFntS, fontStyle );
|
||||
var idSz = app.charIDToTypeID( "Sz " );
|
||||
var idPnt = app.charIDToTypeID( "#Pnt" );
|
||||
formatting.putUnitDouble( idSz, idPnt, fontSize );
|
||||
var idClr = app.charIDToTypeID( "Clr " );
|
||||
var colorAction = new ActionDescriptor();
|
||||
var idRd = app.charIDToTypeID( "Rd " );
|
||||
colorAction.putDouble( idRd, colorArray[0] );
|
||||
var idGrn = app.charIDToTypeID( "Grn " );
|
||||
colorAction.putDouble( idGrn, colorArray[1]);
|
||||
var idBl = app.charIDToTypeID( "Bl " );
|
||||
colorAction.putDouble( idBl, colorArray[2] );
|
||||
var idRGBC = app.charIDToTypeID( "RGBC" );
|
||||
formatting.putObject( idClr, idRGBC, colorAction );
|
||||
textRange.putObject( idTxtS, idTxtS, formatting );
|
||||
actionList.putObject( idTxtt, textRange );
|
||||
textAction.putList( idTxtt, actionList );
|
||||
action.putObject( idT, idTxLr, textAction );
|
||||
app.executeAction( idsetd, action, DialogModes.NO );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function layers(lyrs) {
|
||||
if (typeof lyrs === 'undefined')
|
||||
return;
|
||||
var str = "";
|
||||
for (var i = 0; i < lyrs.length; i++) {
|
||||
var lyr = lyrs[i];
|
||||
str += ('{"Name":"' + lyr.name + '", "Bounds": [[' + lyr.bounds[0] + ',' +
|
||||
lyr.bounds[1] + '],[' + lyr.bounds[2] + ',' +
|
||||
lyr.bounds[3] + ']], "Visible": ' + lyr.visible+', "TextItem": ').replace(/ px/g, "");
|
||||
if (lyr.kind == LayerKind.TEXT) {
|
||||
str += ('{"Contents": "'+lyr.textItem.contents+'",').replace(/\r/g, '\\r');
|
||||
str += (' "Size": '+lyr.textItem.size+',').replace(/ pt/g, '');
|
||||
str += ' "Font": "'+lyr.textItem.font+'"}\n'
|
||||
} else
|
||||
str += "null";
|
||||
str += "}";
|
||||
if (i+1 != lyrs.length)
|
||||
str += ',';
|
||||
}
|
||||
return str
|
||||
}
|
||||
11
runner/scripts/moveLayer.jsx
Normal file
11
runner/scripts/moveLayer.jsx
Normal file
@@ -0,0 +1,11 @@
|
||||
#include lib.js
|
||||
var stdout = newFile(arguments[0]);
|
||||
var lyr = eval(arguments[1]);
|
||||
lyr.translate((Number)(arguments[2]), (Number)(arguments[3]));
|
||||
if (lyr.typename == 'LayerSet') {
|
||||
lyr.merge()
|
||||
lyr=eval(arguments[4])
|
||||
Undo();
|
||||
}
|
||||
stdout.writeln('{' + bounds(lyr) + '}')
|
||||
stdout.close();
|
||||
9
runner/scripts/open.vbs
Normal file
9
runner/scripts/open.vbs
Normal file
@@ -0,0 +1,9 @@
|
||||
' Open photoshop.
|
||||
Set app = CreateObject("Photoshop.Application")
|
||||
if WScript.Arguments.Count = 0 then
|
||||
WScript.Echo "Missing parameters"
|
||||
else
|
||||
path = wScript.Arguments(0)
|
||||
Set doc = app.Open(path)
|
||||
wScript.echo doc.Name
|
||||
end if
|
||||
8
runner/scripts/quit.vbs
Normal file
8
runner/scripts/quit.vbs
Normal file
@@ -0,0 +1,8 @@
|
||||
' Close Photoshop
|
||||
Set appRef = CreateObject("Photoshop.Application")
|
||||
|
||||
Do While appRef.Documents.Count > 0
|
||||
appRef.ActiveDocument.Close(CInt(wScript.Arguments(0)))
|
||||
Loop
|
||||
|
||||
appRef.Quit()
|
||||
12
runner/scripts/save.vbs
Normal file
12
runner/scripts/save.vbs
Normal file
@@ -0,0 +1,12 @@
|
||||
Set appRef = CreateObject("Photoshop.Application")
|
||||
dlgMode = 3 'No dialog
|
||||
set d = CreateObject( "Photoshop.ActionDescriptor" )
|
||||
Call d.PutEnumerated(appRef.CharIDToTypeID("PGIT"), appRef.CharIDToTypeID("PGIT"), appRef.CharIDToTypeID("PGIN"))
|
||||
Call d.PutEnumerated(appRef.CharIDToTypeID("PNGf"), appRef.CharIDToTypeID("PNGf"), appRef.CharIDToTypeID("PGAd"))
|
||||
|
||||
SET desc = CreateObject( "Photoshop.ActionDescriptor" )
|
||||
Call desc.PutObject( appRef.CharIDToTypeID("As "), appRef.CharIDToTypeID("PNGF"), d)
|
||||
Call desc.PutPath( appRef.CharIDToTypeID("In "), wScript.Arguments(0))
|
||||
Call desc.PutBoolean( appRef.CharIDToTypeID("Cpy "), True )
|
||||
|
||||
Call appRef.ExecuteAction(appRef.CharIDToTypeID("save"), desc, dlgMode)
|
||||
1
runner/scripts/start.vbs
Normal file
1
runner/scripts/start.vbs
Normal file
@@ -0,0 +1 @@
|
||||
set app = CreateObject("Photoshop.Application")
|
||||
6
runner/scripts/test.jsx
Normal file
6
runner/scripts/test.jsx
Normal file
@@ -0,0 +1,6 @@
|
||||
#include lib.js
|
||||
var f = newFile(arguments[0]);
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
f.writeln(arguments[i]);
|
||||
}
|
||||
f.close();
|
||||
3
runner/scripts/test.txt
Normal file
3
runner/scripts/test.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
C:\Users\Spencer\go\src\github.com\sbrow\ps\runner\scripts\test.txt
|
||||
arg1
|
||||
arg2
|
||||
3
runner/scripts/test.vbs
Normal file
3
runner/scripts/test.vbs
Normal file
@@ -0,0 +1,3 @@
|
||||
for i=0 to wScript.Arguments.length-1
|
||||
wScript.echo wScript.Arguments(i)
|
||||
next
|
||||
Reference in New Issue
Block a user