diff --git a/v2/Test.json b/v2/Test.json new file mode 100644 index 0000000..33e857c --- /dev/null +++ b/v2/Test.json @@ -0,0 +1,79 @@ +{ + "Name": "Test.psd", + "FullName": "~/go/src/github.com/sbrow/ps/v2/Test.psd", + "Height": 600, + "Width": 900, + "ArtLayers": [ + { + "Name": "Background", + "Bounds": [ + [ + 0, + 0 + ], + [ + 900, + 600 + ] + ], + "Color": [ + 0, + 0, + 0 + ], + "Stroke": [ + 0, + 0, + 0 + ], + "StrokeAmt": 0, + "Visible": true, + "TextItem": null + } + ], + "LayerSets": [ + { + "Name": "Group 1", + "Bounds": [ + [ + 0, + 0 + ], + [ + 0, + 0 + ] + ], + "Visible": true, + "ArtLayers": [ + { + "Name": "Layer 1", + "Bounds": [ + [ + 222, + 290 + ], + [ + 472, + 454 + ] + ], + "Color": [ + 0, + 0, + 0 + ], + "Stroke": [ + 0, + 0, + 0 + ], + "StrokeAmt": 0, + "Visible": true, + "TextItem": null + } + ], + "LayerSets": [] + } + ] +} \ No newline at end of file diff --git a/v2/Test.psd b/v2/Test.psd index 129ebca..1e1b817 100644 Binary files a/v2/Test.psd and b/v2/Test.psd differ diff --git a/v2/document.go b/v2/document.go index 805fed9..20d887c 100644 --- a/v2/document.go +++ b/v2/document.go @@ -130,16 +130,16 @@ func ActiveDocument() (*Document, error) { log.Println("Loading ActiveDocument") d := &Document{} - byt, err := DoJS("activeDocName.jsx") + byt, err := DoJS("activeDocFullName.jsx") if err != nil { return nil, err } - d.name = strings.TrimRight(string(byt), "\r\n") + d.fullName = strings.TrimRight(string(byt), "\r\n") if Mode != Safe { err = d.Restore(d.DumpFile()) switch { case os.IsNotExist(err): - log.Println("Previous version not found.") + log.Printf("Previous version not found: \"%s\"\n", d.DumpFile()) case err == nil: return d, err default: @@ -202,6 +202,10 @@ func (d *Document) DumpFile() string { log.Println(err) } path := filepath.Join(strings.Replace(d.fullName, "~", usr.HomeDir, 1)) + path = strings.TrimPrefix(path, `\`) + path = strings.Replace(path, `[^:]\`, `:\`, 1) + drive := filepath.VolumeName(path) + path = strings.Replace(path, drive, strings.ToUpper(drive), 1) return strings.Replace(path, ".psd", ".json", 1) } diff --git a/v2/ps.go b/v2/ps.go index 1d2105f..69e8a2d 100644 --- a/v2/ps.go +++ b/v2/ps.go @@ -141,6 +141,7 @@ func Quit(save SaveOption) error { } // SaveAs saves the Photoshop document to the given location. +// // TODO(sbrow): doesn't return error on non-existant path. func SaveAs(path string) error { _, err := runner.Run("save", path) return err diff --git a/v2/runner/scripts/activeDocFullName.jsx b/v2/runner/scripts/activeDocFullName.jsx new file mode 100644 index 0000000..fbf3b13 --- /dev/null +++ b/v2/runner/scripts/activeDocFullName.jsx @@ -0,0 +1,2 @@ +#include lib.js +var stdout = newFile(arguments[0]);stdout.writeln(app.activeDocument.fullName);stdout.close(); \ No newline at end of file diff --git a/v2/runner/scripts/test.jsx b/v2/runner/scripts/test.jsx index 280da5f..df892c5 100644 --- a/v2/runner/scripts/test.jsx +++ b/v2/runner/scripts/test.jsx @@ -1,4 +1,5 @@ #include lib.js +alert(app.activeDocument.path) var f = newFile(arguments[0]); for (var i = 0; i < arguments.length; i++) { f.writeln(arguments[i]); diff --git a/v2/test.log b/v2/test.log new file mode 100644 index 0000000..0daa85a --- /dev/null +++ b/v2/test.log @@ -0,0 +1,10 @@ +2018/08/20 17:09:51 Loading ActiveDocument +2018/08/20 17:09:51 Previous version not found: "C:\Users\Spencer\go\src\github.com\sbrow\ps\v2\Test.json" +2018/08/20 17:09:51 Loading manually (This could take awhile) +2018/08/20 17:09:51 Loading ActiveDocument/Group 1/ +2018/08/20 17:09:51 Dumping to disk +2018/08/20 17:09:51 C:\Users\Spencer\go\src\github.com\sbrow\ps\v2\Test.json +2018/08/20 17:09:52 Dumping to disk +2018/08/20 17:09:52 C:\Users\Spencer\go\src\github.com\sbrow\ps\v2\Test.json +2018/08/20 17:09:52 Loading ActiveDocument +2018/08/20 17:09:52 Previous version found, loading