Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obligatory Space replacement in filenames #25

Closed
stigzler opened this issue Sep 22, 2014 · 11 comments
Closed

Obligatory Space replacement in filenames #25

stigzler opened this issue Sep 22, 2014 · 11 comments
Labels

Comments

@stigzler
Copy link

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
Copy link
Collaborator

skjorn commented Sep 22, 2014

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
Copy link
Owner

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
Copy link
Author

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:

  • Auto-create folders from Group names on export
  • A 'switch' in the group name to specify whether the export is to be a single flattened .png from a number of layers in a group OR individual exports of each layer within each group (as per present). The switch could be at the end of the group name, after a minus or something? e.g. "Buttons-f" = flatten or -i = individual?
  • Dunno if this is possible, but to export to the layer size rather than the canvas size? Having to Smart Object it, Edit then print from resulting psb...

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
Copy link
Collaborator

skjorn commented Sep 23, 2014

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:

  • Folders from group names are actually on the wish list (see Export groups as folders #17).
  • Switches in names... There's an earlier fork around here somewhere that already implemented it. I don't really like it being a part of this script myself. It feels like a hack and project specific too. It just overcomplicates things and makes the script bloat. People might name their layers differently and might be not aware of this magic interpretation. I would prefer it to be a separate step. One script to pre-process the PSD based on switches or whatever, this one, and possibly one to combine them together into a single step. In other words, it calls for another project.
  • Layer sizes... There's a plan to add trimming options (see Trim Layers to Images #5). But I've never actually worked with Smart Objects. Not sure if there's even access from scripting API. Maybe if you could describe what you're doing with them in detail, we could consider how they fit into the big picture.

@antipalindrome
Copy link
Owner

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
Copy link
Collaborator

skjorn commented Sep 23, 2014

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

@skjorn
Copy link
Collaborator

skjorn commented Sep 23, 2014

It's actually very similar to #21.

@stigzler
Copy link
Author

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

@skjorn
Copy link
Collaborator

skjorn commented Sep 23, 2014

@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
Copy link
Author

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
Copy link
Collaborator

skjorn commented Sep 24, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants