Can't read or write files in ScriptUI Folder
Hi all, I am having trouble with a dockable script that I am doing.
My error was when I finished it and tried to put the ScriptUI folder to test it and see that it didn't work, I tried it before without any icon applied and it worked fine.
Assuming Allow script access to script files is enabled, if I run the script from the desktop it works perfectly and there are no problems creating or reading files, but in ScriptUI Folder it is impossible to do so. I recreate the problem by creating a simple user interface with a binary icon that creates a folder for the temporary image and other things that I need to put in my actual script.
What am I doing wrong?
Why can't I read or write files to the ScriptUI folder and yes to the desktop or another folder?
function myScript(thisObj){
function myScript_buildUI(thisObj){
var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "test", undefined, {resizable: true, closeButton: true});
var resMain = "group{ orientation:'column', \
main_panel: Group { type: 'group', orientation: 'column', \
but_img: IconButton { preferredSize: [30,30] },\
},\
}";
var imgNRM = "\u0089PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x00\x19\x00\x00\x00\x19\b\x06\x00\x00\x00\u00C4\u00E9\u0085c\x00\x00\x01\x15IDATH\u0089\u00ED\u0093=NBA\x14\u0085\u009F$\u00C6\u00C2P[\u00DA\u00DA\u00D8\u00D3\u00B8\x01\x12(\u00E8\u00F0)F\x13\u008AW\x00\r;\u00B0\u00A2\u00A3t\x05\u00AE\u00C0\r\u00B8\x00\x12z\n\n\x13\u00B5\u00B2\u00B01\u0082\u00E43\x13\x0E\u00C9-\u00DE\u00BB\u00A3\t\u00E5\u009Cn\u00CE|g\u00CE\u00FCd\u00B2\u00A4\u00A4\u00A4\u00FF\x0Bh\x03\u00AF\u00C0\u00B5\x17\x06\x1E\u0081\x0F\u00E0$\u00B0\u00CA\u00B4\u00A3\u0085@\x17X\u00B1\u00D5\u00A5\u00C3\u00DD\u0088y\x03\u00EA\u0081\u00D58d\u00BB^A\u00D8\u00CDFp\u00E1p\u00A7\u00C0\u00A7\u00B8\u00A6\u00F1\x0Bya\u008D\u00AB\u00B2\u00A0\x05n\u009D\u0082\x1A\u00F0,\u00F6\u00A1d\u00FE\u00AEt\u00A3\u00C0\u00C8\x14\u00E4\u0095G\u00DD\u00B2c\u00B1\x0B\u00E0\u00B8\u0082\u00C9M\u00D1hg\u00AEeL#\x05\u00E7\u00C07\u00F0\x034\"\u00ECTk\u00AEwF\x11;\tp\x04\u00CC\u00C5\u00DDG\n\u00F2\u00AA+\u00EBkbS\u00F6\u00E8\u00C0D\u00A1\x19p\u00E8\x14\x14f\u009D~l\x07\x03\u00E3_\u00C8\u00FF\x02\u00CE\u009C\u0082\u00C1\u009F\u00DE\x16\u00E8\u0098\x7F\u00D2\u00D35-5\x1E:\u00B9\u009E\u00F9'\u009D\u00CA\x02\x13h\x01/:Y\u00F8h\u00EF\u00C0\x13p\u00E0dreZ\u00D1\u0082\u00A4\u00A4\u00FD)\u00CB\u00B2_y\u00AF\u00C50\u00E5\u00BC\u0081\u00DE\x00\x00\x00\x00IEND\u00AEB`\u0082";
myPanel.grp = myPanel.add(resMain);
var myScriptFilePath = File($.fileName).path; // the URI of the folder that contains the script file
//var myScriptFilePath = "~/Desktop/";
var myScriptFolderPath = myScriptFilePath + encodeURI("/tempFolder"); // the URI of the folder script resources
var myFolder = new Folder(myScriptFolderPath);
if ( ! myFolder.exists ) {
myFolder.create();
}
var myFile = new File(myScriptFolderPath + encodeURI("/tempImage.png"));
myFile.encoding = "BINARY";
myFile.open( "w" );
myFile.write( imgNRM );
myFile.close();
var butImg = myPanel.grp.main_panel.but_img;
butImg.image = ScriptUI.newImage (myFile);
butImg.onClick = function () { alert("bye"); myPanel.close(); }
myPanel.onShow = function () { alert("Hello World"); }
return myPanel;
}
// load, check and show the panel
var myScriptPal = myScript_buildUI(thisObj);
if (myScriptPal != null && myScriptPal instanceof Window){
myScriptPal.center();
myScriptPal.show();
}
}
myScript(this);
}
Hope someone can bring me light on this, thanks in advance!
