antipalindrome / Photoshop-Export-Layers-to-Files-Fast

This script allows you to export your layers as individual files at a speed much faster than the built-in script from Adobe.
MIT License
1.53k stars 427 forks source link

Obligatory Space replacement in filenames #25

Closed stigzler closed 10 years ago

stigzler commented 10 years ago

Hi - loved this - just what I needed for a project - great speedy app that beats the stock one hands down. However, having one major problem with it - it automatically replacing spaces in filenames with underscores. I understand why, but I wish to disable it - I need the spaces in my filenames!!

Tried replacing line 1302: function makeValidFileName(fileName) { var validName = fileName.replace(/^\s+|\s+$/gm, ''); // trim spaces validName = validName.replace(/[*\/\?:"|<>]/g, ''); // remove characters not allowed in a file name //validName = validName.replace(/[ ]/g, '_'); // replace spaces with underscores, since some programs still may have troubles with them return validName; }

Weirdly, filenames returned now with a "-" rather than a "_":

stop_replacing.png > stop-replacing.png

can't find any code anywhere else that puts in a "-"!!!

Please help! I was close to finishing a 6 months project today, but came to a dead stop when hit this. :(

Thanks

skjorn commented 10 years ago

Hi, sorry to hear about that. Depending on the format you use, Photoshop may replace these spaces by itself (when "Save For Web" functionality is used under the hood). Leave the changes you made to the script and follow this guide: http://www.craig.copperleife.com/tech/photoshop_dashed_filenames.htm When finished with settings, just click "Done". It should work then.

antipalindrome commented 10 years ago

Just an additional comment, if you're savvy enough you can look to use something like Windows Powershell to accomplish batch renaming, but skjorn's link should address what you need. http://stackoverflow.com/questions/16636996/replace-or-delete-certain-characters-from-filenames-of-all-files-in-a-folder

stigzler commented 10 years ago

Wow! thanks for the quick reply, Skjorn - and you nailed it! No wonder I couldn't find the issue in yer script - it wasn't there!

Thanks as well, jwa.

I'll check out donations in a sec.

This has proved invaluable in a project I'm working on. Reading elsewhere on this project, I see there's been suggestion of a few other things that would mean your script would be a 1-click deal in a very complicated export task. Details of my project here:

https://dl.dropboxusercontent.com/u/15144043/Tagger%20Blagger/GameTagger%20Blagger%20Readme.pdf

The functions that would make this killer are:

Thanks again chap. It's almost like true altruism + creation lies with coders these days. My hobby+projects would be lost without you guys. :)

skjorn commented 10 years ago

Thanks for your suggestions. Glad we could help :-) I guess this project is sort of pure altruism. I use the script fairly frequently on my projects and I thought why not make my improvements public. I've spent a lot of time on them (actually never scripted in Photoshop before this :-) ), so others don't have to.

Considering your proposals:

antipalindrome commented 10 years ago

Thanks @stigzler.

I'd also like to address the second point you've made. If you have access to Photoshop CC you can actually export layer groups as flattened images by appending the group name with ".png" or ".jpg" or what have you. Then going to File -> Generate -> Image Assets.

That being said, if you don't have Photoshop CC then that option becomes unavailable to you. So I think @skjorn that we could add functionality as requested, without it needing to be hacky by using a similar syntax as Adobe uses. We could even have a checkbox where they can opt-out of it flattening layer groups even with the extension.

Just a thought!

skjorn commented 10 years ago

Interesting thought. We could do something like this if it's in line with standard functionality I guess.

skjorn commented 10 years ago

It's actually very similar to #21.

stigzler commented 10 years ago

thanks fellas. And nice steer jwa - have got cc - so will look into this

skjorn commented 10 years ago

@stigzler By the way, I added an option to leave spaces in file names, so you don't have to hack it and maintain future updates. You can reference this script directly. I also made the dialog appear faster for documents with many layers, so it shouldn't be such a pain to cancel and come back if you forget something.

stigzler commented 10 years ago

Sounds spot on, skjorn - thanks fella!! That faster dialogue is a godsend too. Many thanks. Did have a go with PS Genrator. Whilst it looks quite good - lacking atm one major component which is exporting images to canvas rather than [layer?] size. Also, quite fussy with filenames. Therefore sticking with your script at the moment - I'll be sure to mention you guys in my project doc acknowledgements. Will follow with interest any future updates giving folder creation options. Will also make sure direct reference to yourselves in the amended readme.

skjorn commented 10 years ago

PS Generator looks cool and is open source, too. Finally a step in the right direction from Adobe.