Skip to main content
schroef
Inspiring
August 24, 2017
Question

Loading icons windows

  • August 24, 2017
  • 2 replies
  • 7982 views

Im busy making a script which stitches images together using row by row and column by column method. Ive added a couple of script together into one script.

To make the stitch method more clear i made 2 icons. Problem is that windows users get errors when the images need to be loaded.

The icons are placed in the main script folder in the presets folder /Photoshop/Presets/Scripts/row-row.png. Im using OSX as system and there i could use "../row-row.png". This doesnt seems to work properly on windows. So i tried using backslash, but this give errors in the code as the backslash is for include specials.

This is the part which loads the png images;

var f = new File("../blanco.png");

var f1 = new File("../row-row.png");

var f2 = new File("../col-col.png");

I also tried this;

if (File.fs == "Windows"){

     var f = File("..\blanco.png");

     var f1 = File("..\row-row.png");

     var f2 = File("..\col-col.png");

}

if (File.fs == "Macintosh"){

     var f = File("../blanco.png");

      var f1 = File("../row-row.png");

      var f2 = File("../col-col.png");

}

What is the best method to get windows look in the current folder of the presets/scripts/ folder?

This topic has been closed for replies.

2 replies

Tomas Sinkunas
Legend
August 24, 2017

If you are using these images as icons in your ScriptUI panel, I would recommend converting them to binary strings at first and then applying those in code. Here's a small example:

(function(){

    var win = new Window("dialog", "script");

    var cameraImg = "\u0089PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x00H\x00\x00\x00H\b\x03\x00\x00\x00b3Cu\x00\x00\x00\u0081PLTE\u00FF\u00FF\u00FFJJJ\u00F7\u00F7\u00F7\u00C8\u00C8\u00C8NNN\u0080\u0080\u0080\u00EE\u00EE\u00EEyyy\u00F3\u00F3\u00F3ddd\u00A4\u00A4\u00A4LLL\u00D3\u00D3\u00D3WWW\u00DC\u00DC\u00DC\u00D9\u00D9\u00D9\u009A\u009A\u009Appp\\\\\\\u00A1\u00A1\u00A1VVV\u00FC\u00FC\u00FC\u00EB\u00EB\u00EB\u00E1\u00E1\u00E1\u00A7\u00A7\u00A7lll\u00F9\u00F9\u00F9\u00CE\u00CE\u00CE\u00C2\u00C2\u00C2\u00A0\u00A0\u00A0\u009F\u009F\u009F\u0096\u0096\u0096\u0087\u0087\u0087___RRR\u00CD\u00CD\u00CD\u00AB\u00AB\u00AB\u0083\u0083\u0083}}}\u00AD\u00AD\u00AD\u0091\u0091\u0091ttt\u00B0\u00B0\u00B0\u0089\u00B5\u00C9\u00E1\x00\x00\x01\u0083IDATX\u00C3\u00ED\u0096\u00E9r\u00820\x14F\u00EF\x07a\u0093\u00ADl\u008A\u008A\u008A\u00BB\u00F6\u00FD\x1F\u00B0\x0E\u009DB\x01c\u0082Lu\u00A6\u0093\u00F3/\u00DCpHHroH\u00A1P(\u00FE\u0096Eqd\u00A8a\u00C7b\u00F1\u009CG\u00BB\u00A2\u00C3U{Jt\u0081\x7F^\u00FC\x1A\u00DF\u00D9\u00C7\u0085\u00A4\u0098\u00E0\u009BI\u00D5\u009A\u00BAl\u00D6\u008E\u00CF\u0098;\u0095\x12\u00E1\u0087\u00AA\u0095\u00A3\u00A4\x0E%r\x12\u0093\x15@\u00DB\u00B7\u00A7\x0E{\u00DC\u0088\u008D\u00DC|\u00E4\u00F1\x1C\u00E0\u00D8\u009AaI=JT\u00A4:\u00DF\u00B3wa\x15\x19I`\u00EA\x06\\\u00AE\u00C9\u008E\u00F1I\u00D2\x1C\u00E0\u00DB\u009CP\x0E\u00E3~`\u00AAO\u008C86&zk\u00BDNH8\u00A29<\u00A2e\x14-\u00A9Eh\u00A1\u00C6\n\u00A9\u00C6\u0083\u00C3\x111hD\x0E\u00DAqm\x03\u00A4\u00B7\u00C1\u0098\u00E6mX)\u00B0\u00D1\u00EA\b\x18w\x0BQOdG`\u00AB\u00E6\u00DD\x15Cd7\u00FD\u00F9\u00A2\u00EE\u00D42\x0B\u00CE\u00AC\u00B5\u00B1\x1DX\u0099\u0084\u00A8K\u0082\u00AD\u00D9Y\u00F8-\u0092\u00E1\u00A2\u00C0e!u\b\u0099\x1B\f\x16YXS\u008F5\u00AC\u00A1\u00A2\x00\u00BEF=4\x1F\u00C1@\u00D1\x07>\u00A8\u00A2\u00F7X,\u00EA\u00EF\u00D0>\x1E\u00E6\x03E;\u00D8w\u00CF$v\x03E\x00\u00AF\u00E3\u00ABE\u00E2\u00A9\u00BD\u00FAg\u008B\u0097\u00FF=\x1BR|D\u00C6\x1F\u00DA\u00F7\u00A5\u0091\u00F1\u0089m|\u00AA\u00AD\x10$\x7F\u00A1\u0088\u00A1\u00EE$(G\u0082*\u00E2\u00C0\x13\x17H\u0099\u00BA\u0096\u00E0D\x02\u00E4*\u00AD\u00ED\u00E30\u00A6\u00F67\u00E8.\f\u00DD\x1Cq\x1BiL)\u00A4I\u00F5\u0087_\u00CA\u008D\x18\x02\u00EA\x1B\u009BB\u00A1P\u00FCs\u00BE\x00g\u00E7\x12\u0097\x1B\u00EF*\x01\x00\x00\x00\x00IEND\u00AEB`\u0082";

    var btn = win.add("iconbutton", undefined, cameraImg);

    win.show();

})();

I wrote this script some time ago that takes bunch of files and converts them to binary strings. AE Script: Export to Binary String — Bitbucket  It works for both Photoshop and After Effects. Should probably be able to run on Illustrator, but I haven't tried it yet.

Simply launch this script, select your images, copy/paste binary strings to your code and you should be golden.

This will avoid distributing your physical image files and will save you time and headache in case end user will remove those images from hard drive.

Hope that helps.

Davide_Barranca12040269
Legend
August 25, 2017

https://forums.adobe.com/people/Tomas+Sinkunas  wrote

[...]

This will avoid distributing your physical image files and will save you time and headache in case end user will remove those images from hard drive.

I've been doing that for some time, but it has happened that users (few ones, luckily) may complain about script failures due to missing/invalid image data. For them, I've resorted to compiling a custom version with PNGs. Unfortunately, I've never been able to narrow down the issue to any meaningful set of causes. Has that ever happened to you?

Davide

Davide Barranca - PS developer and authorwww.ps-scripting.com
Tomas Sinkunas
Legend
August 25, 2017

Hey Davide Barranca​.

I've never had issues with binary images. Lloyd Alvares from AEScripts.com always recommends this method, as users might lose images and whatnot.

So when ever I do AE script, this is the workflow I use.

Cheers.

Chuck Uebele
Community Expert
Community Expert
August 24, 2017

For windows if I want to put in in the PS scripts folder, I use:

var file = new File (app.path + '/Presets/Scripts/myImage.png');

schroef
schroefAuthor
Inspiring
August 24, 2017

Thanks! ill try that. So forward slash would work then actually. What i dont get is why "../image.png" wont work in Windows. I got a user reporting error the about wrong image data.

schroef
schroefAuthor
Inspiring
August 24, 2017

Looking again at yours, this should do the same. Yet i got a error by the user again.

var FolderPath = app.path + "/"+ localize("$$$/ScriptingSupport/InstalledScripts=Presets/Scripts");

var f = File(FolderPath + "/blanco.png");

var f1 = File(FolderPath + "/row-row.png");

var f2 = File(FolderPath + "/col-col.png");