Copy link to clipboard
Copied
I have a simple UI for my artists that does some modifications to his files then saves it to the folder of his choice.
However it gets quickly tedious to re-enter the path every time he uses the script.
I would like to remember the path he previously entered or use the path that Photoshop uses as a default.
How can that be done?
Here's the script if someone is interested, it allows you to save out your groups as PNG's with possible additional blurred versions:
Photoshop PNG Blur Save - Pastebin.com
Message was edited by: Jeremy Vansnick
Change beginning of your script to:
PTH = ""; displayDialogs = DialogModes.NO
var Path = $.getenv('pth') || PTH || "d/";
// for saving files
var doc = app.activeDocument;
And in the middle where you last time insterted new part, edit that to:
dlg.show();
$.setenv('pth', Path.slice(1))
if (PTH != ge = $.getenv('pth')) {
(fle = File($.fileName)).open('r'), jsxFile = fle.read()
.replace(/"(.*)"(?=;)/, '"' + ge + '"'), fle.close()
fle.open('w'), fle.write(jsxFile), fle.close()
}
Additionally what
...Copy link to clipboard
Copied
Ah sorry, alert / sleep should be before vbs.execute(). Or you may change order, putting eval before document:
fle.write(rep), fle.close(), eval(p + ' = 1'), documents.add(1,1,1).close()
For me all works good, but for you there must be done little change, question is where, but I think it's that one.
Forget about proposed solution, it wont help for sure. I found cause of this confusion. Theres need of delay between running your script first time, and second when autoUpdateOpenDocuments is set to false. In your case script was reran too fast, so either preferences couldn't be changed or there wasn't enough time they could impact for document refreshment. Only you have to do is to add WScript.Sleep 250\r at beginning of vbs code that is saved to executable file. Change those 4 lines then:
txt = 'CreateObject("Shell.Application").ShellExecute """'
txt += Folder.startup.fsName + '\\Photoshop.exe""", "'
txt += File(fN).fsName + '"', vbs.open('w')
vbs.write(txt), vbs.close(), vbs.execute()
to these 3:
t = 'WScript.Sleep 250\rCreateObject("Shell.Application").ShellExecute """'
t += Folder.startup.fsName + '\\Photoshop.exe""", "' + File(fN).fsName + '"'
vbs.open('w'), vbs.write(t), vbs.close(), vbs.execute()
Test it to make sure it works. If not change 250 to 750. Then make the same change in your script, and test it to see all is ok.
So the corrected code is now:
#target photoshop
if (vbs = File((fN = $.fileName).slice(0, -3) + 'vbs'),
!(eval(p = 'preferences.autoUpdateOpenDocuments'))) {
(function(){
(fle = activeDocument.fullName).encoding = 'binary', fle.open('r')
var rep = fle.read().replace(/\x018BIMp/g, '\x028BIMp'); fle.open('w')
fle.write(rep), fle.close(), documents.add(1,1,1).close(), eval(p + ' = 1')
t = 'WScript.Sleep 250\rCreateObject("Shell.Application").ShellExecute """'
t += Folder.startup.fsName + '\\Photoshop.exe""", "' + File(fN).fsName + '"'
vbs.open('w'), vbs.write(t), vbs.close(), vbs.execute()
})()
}
else eval(p + ' = ' + !p), vbs.remove()
If you want your artists have retrieved state of layer sets at the end of script process, add activeDocument.save(), to make:
if (vbs = File((fN = $.fileName).slice(0, -3) + 'vbs'),
!(eval(p = 'preferences.autoUpdateOpenDocuments'))) {
activeDocument.save()
At end you can add your alert (but test it also without):
else eval(p + ' = ' + !p), vbs.remove(), alert("Finished exporting files")
while content of function in middle of code replace to:
(fle = activeDocument.fullName).encoding = 'binary', fle.open('r')
var r = fle.read(); fle.open('w'), fle.write(r), fle.close(), eval(p + ' = 1')
documents.add(1,1,1).close(), t = 'WScript.Sleep 250\rCreateObject'
t += '("Shell.Application").ShellExecute """' + app.path.fsName
t += '\\Photoshop.exe""", "' + File(fN).fsName + '"'
vbs.open('w'), vbs.write(t), vbs.close(), vbs.execute()
Copy link to clipboard
Copied
Thanks, all my tests have functioned as intended with this! Good job
I guess it does save the document so I hope that won't cause a problem to my artists; what if the artist decided to save out some png's as a test but without saving his document. I'll have to ask them about that.
Since it saves in the beginning of the script I think it's not that big a deal. If it saved during the process or after that'd be a big deal because the script could have changed his psd in unwanted ways
Copy link to clipboard
Copied
Alternative is to not saving document at beginning of script but only at its end save read binary to file (so information from before running script). That won't save changes made by artist to the .psd document, but only retrieve .psd document last state, so from time that wes opened (if not saved by artist meantime, so before some changes were made on layers). The difference will be that at end of script the document won't be restored to moment script was started but to the time it was opened. It's also risky because your artists from time they opened document could make changes they wanted to keep, but didn't save them. So then they ran script which at end restored original document state, while they thought they're going to see document state from time script was ran. If you want so, and there is still occurance some of them want to keep some changes made beetween opening document and running script, they have to remember to save them otherwise they lose some work.
Copy link to clipboard
Copied
Well that's ok I think it's best to leave it as it is then. Thanks for all the help, much appreciated!
Copy link to clipboard
Copied
Actually you can comment that saving line. So when process of script is finished it'll restore document last saving / opening state. But layer sets opened by them before running script won't be considered. So other way of doing it is to at beginning of script save copy of current document. When script is at its end it will read only layer sets state from document copy to apply it to original document binary data. Then copy of original psd will be deleted while original psd displayed with original state (from time that was opened) so without changes made, however with state of layer sets made by artists till script launching.
And edit your pastebin code, as you left there that part that script doesn't work with, so others can use it when it's corrected.
Copy link to clipboard
Copied
Ok it's updated, I still had a little bug where it would render 2 props when doing blurred versions and it's now fixed:
Photoshop:PngGroupSave - Pastebin.com
Copy link to clipboard
Copied
If the path entered is not correct the script will resize the document amongst other unwanted things...
Is there a way I could check if the given path is correct? this way I wouldn't modify the .psd for no reason.
Copy link to clipboard
Copied
I wanted to suggest you to use .exists for checking existment of certain path, but you found it yourself
One tip for you. That typing into blank a path is very lame. Better do that the way you find in this script:
Copy link to clipboard
Copied
Alright, I'll add that right now.
It seems I have another bug however, well my artist does.
Sometimes the alert box that says the operation is finished doesn't come up but somehow the sprites are saved and the autoUpdate is set to true in the preferences. It's like the whole script runs fine except for the last line, I don't get what happens.
Copy link to clipboard
Copied
I saw in your script you still use old gaussain blur function (however changed). I tried something new, and if you use it your script will be working 30% faster, so for example not 10, but 7 seconds for 3 layers (while that was difference of 30 seconds for 10 times more layers) to use gaussian blur for as that is based on current layer dimension, not on canvas after trimming:
Math.blur = function(v1, v2) {
with(this) {
(b = result.bounds), result.applyGaussianBlur
(v1 * sqrt((b[2] - b[0]) * (b[3] - b[1]) / pow(v2, 2)))
}
}
Math.blur(blurStrength, 512)
The results are almost same, but perhpas even more precise, so if before you had blur 5.1, now that can be 5.9, or if 4.1 then 4.2, sometimes 19.3 can be 20.3. There's no rule. It simply measures bounds of layer that differs a little from trimmed canvas.
When alert does not pop up is .vbs file from your script folder deleted while "Auto-Update Open Documents" box unfilled?
Copy link to clipboard
Copied
Ah very cool, it does take a long time to operate that's definitely a fact. It feels like it goes faster now with what you suggested.
I'm not sure about your question because I can't replicate the bug on my machine so far. He also has Windows10 (same as me). I'm going to try some more to replicate his bug. He said it bothered him that the alert didn't trigger when he had PS minimized.
I'll post soon to tell you if I was able to replicate his bug. I haven't implemented the search path in Windows for now but I definitely will, a really cool thing would be to also have a list of previous paths but that's just fancy stuff. For now I'd rather make the script work all the time on any machine first and maybe optimize it some more.
EDIT: I can't replicate the bug he has, I'm going to try it on his computer some more, I'll try making it sleep to 750 on his computer maybe that's the issue.
I couldn't find any .vbs files in the script folder while running the script, is that a file you write information to during the script?
Copy link to clipboard
Copied
That I know when you minimize window after running script it's going to ask you question do you want to save changes made to file from last opening (those done to binary by script) every time you want to run script again (if you minimized windows again). I had with it problem but solved it that doesn't shows up anymore but didn't know your users will leave Photoshop during process. That is no problem after all. Only need to additionally click 'OK' button, or open new document to close it without saving, so a thing there happen when script is working but has effect only there's photoshop window on your screen.
Well tell him to not minimze Photoshop when he run script just for test, to see this situation with no showing alert will happen again.
Copy link to clipboard
Copied
Ok I ran a few tests on his computer, here's what I know now:
- minimized or not, the result is the same (no alert is given).
- groups are properly closing and staying opened.
- sleeping longer doesn't matter
- no vbs file is present in his scripts folder
- autoUpdate is true despite being false when starting script
Here's the script: normally nothing really changed except for the optimization you just told me about (Photoshop:PngGroupSave - Pastebin.com)
Copy link to clipboard
Copied
You said "sometimes" alert doesn't come up, so sometimes it comes up or never?
You can't see .vbs file during script's work as it's beeing created only for few miliseconds. If that was not removed then you can see it is present in script folder, so 'Auto-Upadate Open Documents' option was true still while end alert couldn't come up. All because 'else' statement wasn't launched. But it's not present while alert doesn't come up and A-UOD option is set to true. Cause is .vbs wasn't created at all, so couldn't rerun script to set AUOD to false and remove itself to come up with alert.
The only I do not understand why it happens sometimes? Maybe it worked well but then stopped completetly, but he said sometimes like that still worked from time to time? Check his (parents) script folder permissions, clicking with right mouse button and choosing last item, Properties. Maybe you have to Edit groups and users in Security tab, that they got full access.
Ps: you didn't read carefuly. I didn't say to remove function, but only replace its content. See how function originally looked in reply 32: Re: UI: Remember last path entered and how that had to look in no.50: Re: UI: Remember last path entered where I said to replace function content, not a current function with a code I posted That possibly may solve problem...
After you do above and still that doesn't work like should then this code save as separate script:
if (vbs = File((fN = $.fileName).slice(0, -3) + 'vbs'),
!(eval(p = 'preferences.autoUpdateOpenDocuments'))) {
(function(){
(fle = activeDocument.fullName).encoding = 'binary', fle.open('r')
var r = fle.read(); fle.open('w'), fle.write(r), fle.close(), eval(p + ' = 1')
documents.add(1,1,1).close(), t = 'WScript.Sleep 250\rCreateObject'
t += '("Shell.Application").ShellExecute """' + app.path.fsName
t += '\\Photoshop.exe""", "' + File(fN).fsName + '"'
vbs.open('w'), vbs.write(t), vbs.close()//, vbs.execute()
})()
}
else eval(p + ' = ' + !p), vbs.remove(), alert("Finished exporting files")
While there is saved document in Photoshop and AUOD set to false run above code and check was there created .vbs file in script folder while AUOD is true. If that is then run it again and see is it removed while AOUD false again. If it is, uncomment vbs.execute(), save and see isn't there .vbs file in script folder and is AUOD set to true and did alert come up.
Copy link to clipboard
Copied
When I tested the alert never came up.
I checked the posts you said but I don't see any difference with my current script (my version is the last REEDIT of post #50), it's not completely clear to me what you mean there. Do I have to add a part from the post #32? Ah ok I just understood with your edit. I do have to add the part from post #32.
Ok I'll go try it with the modified script. I update the pastebin then I go on his computer.
Copy link to clipboard
Copied
I looked into pastebin and see you commented old "function" (as that wasn't put to function), and pasted new function (i.e. old function that is still no present as function). There's lack of components: (function(){ and })(). btw //~ should be just //​.
Copy link to clipboard
Copied
Oh yes, that's ExtendScript's weird way of commenting out.
I don't understand what you mean most of the time, you talk in a manner that I have trouble understanding somehow. Yes I saw there was a mistake in my script.
I changed the pastebin again, I think that's what you want. It runs fine on my computer, I'll try on his now.
Copy link to clipboard
Copied
Still no components: (function(){ and })() in pastebin script surrounding a code (currently line 219 of your script), so like in reply no. 66. What is uneeded you did is that correct part you pasted at beginning of your script (currently its lines 8 to 18).
Copy link to clipboard
Copied
Ok what about now?
Copy link to clipboard
Copied
Now is okey if you didn't change anything else I didn't notice Did you check his script folder properties (reply 66)?
When you do everything on his computer once again then read second part of reply 66 where I attached code (you didn't have to paste to your script what you did, but already deleted), and check on his computer how it works but us SEPARATE script what I wrote. I don't know how you understand this word but that means other script with only that content I posted in reply no. 66.
Copy link to clipboard
Copied
I tried on his computer, it didn't work. On mine it works perfectly.
- I started the script everytime with AutoUpdate set to false in the prefs.
- Privilege on the script folder is set to full access.
- AutoUpdate is left as true because the alert doesn't popup (minimized or maximized) when the operation is finished.
Copy link to clipboard
Copied
I updated last post, read it and use that code from reply no. 66 with instructions you have under that code...
Copy link to clipboard
Copied
Now I go back on his computer and run a new script from post #66.
On my computer: I can see the .vbs file and when I uncomment the vbs.execute() the alert pops up.
On his computer: I get this error https://i.imgur.com/zJTeAJW.png
Copy link to clipboard
Copied
May you edit this script and press enter after delimiter that is in front of t = (to make two separate lines), so we can know it's related to closing created document, or creating .vbs file content. Then save it and run again.
Copy link to clipboard
Copied
It's related to closing the created document (the first line, not the 2nd).
Find more inspiration, events, and resources on the new Adobe Community
Explore Now