From: aRKay on 29 Jul 2010 16:30 I exchange email with a number of unix users and my Mac OS X Screen shot file names are causing them extra work How can I hack 10.6 so it sends something like this Screen_shot_2010-07-29_at_3.26.13_PM rather than this Screen shot 2010-07-29 at 3.26.13 PM How can I ditch the spaces
From: Wes Groleau on 29 Jul 2010 19:07 On 07-29-2010 16:30, aRKay wrote: > Screen_shot_2010-07-29_at_3.26.13_PM > > rather than this > > Screen shot 2010-07-29 at 3.26.13 PM > > How can I ditch the spaces Know anyone who likes perl? I'm not real good at it, but if they're all in one directory, the command would be ls | my-script and my-script would contain something resembling while (<>) { $original = $_; s/ /_/; system("mv \"$original\" $_"); } But don't miss the very important word _resembling_ -- Wes Groleau Review of the article The Overwhelmed Generation in FL Annals http://Ideas.Lang-Learn.us/barrett?itemid=1313
From: Jim Gibson on 29 Jul 2010 20:04 In article <i2t1k3$8i8$1(a)news.eternal-september.org>, Wes Groleau <Groleau+news(a)FreeShell.org> wrote: > On 07-29-2010 16:30, aRKay wrote: > > Screen_shot_2010-07-29_at_3.26.13_PM > > > > rather than this > > > > Screen shot 2010-07-29 at 3.26.13 PM > > > > How can I ditch the spaces > > Know anyone who likes perl? I'm not real good at it, > but if they're all in one directory, the command would > be > > ls | my-script > > and my-script would contain something resembling > > while (<>) > { > $original = $_; > s/ /_/; > system("mv \"$original\" $_"); > } > > But don't miss the very important word _resembling_ Perl has a rename function, so there is no need to use system to call the mv utility. Below is a Perl program that I copied from somewhere many years ago. It works on any Unix-like system. The script is stored as the file 'rename' in a directory that is on my path, so I could rename the screen shot files with the command: rename 's/ /_/g' Screen* Script follows: #!/usr/bin/perl # # rename # # perl script to rename files # # Usage: # # rename perlexpr [files] # ($op = shift) || die "Usage: rename perlexpr [filenames] where perlexpr is any perl expression that modifies \$\_: 's/old/new/' '\$\_ .= \".ext\"' 'tr[A-Z][a-z]'\n"; if( !@ARGV ) { @ARGV = <STDIN>; chop( @ARGV ); } for( @ARGV ) { $was = $_; eval $op; die $@ if $@; rename($was,$_) unless $was eq $_; } -- Jim Gibson
From: aRKay on 29 Jul 2010 20:57 In article <290720101704376516%jimsgibson(a)gmail.com>, Jim Gibson <jimsgibson(a)gmail.com> wrote: > In article <i2t1k3$8i8$1(a)news.eternal-september.org>, Wes Groleau > <Groleau+news(a)FreeShell.org> wrote: > > > On 07-29-2010 16:30, aRKay wrote: > > > Screen_shot_2010-07-29_at_3.26.13_PM > > > > > > rather than this > > > > > > Screen shot 2010-07-29 at 3.26.13 PM > > > > > > How can I ditch the spaces > > > > Know anyone who likes perl? I'm not real good at it, > > but if they're all in one directory, the command would > > be > > > > ls | my-script > > > > and my-script would contain something resembling > > > > while (<>) > > { > > $original = $_; > > s/ /_/; > > system("mv \"$original\" $_"); > > } > > > > But don't miss the very important word _resembling_ > > Perl has a rename function, so there is no need to use system to call > the mv utility. > > Below is a Perl program that I copied from somewhere many years ago. It > works on any Unix-like system. The script is stored as the file > 'rename' in a directory that is on my path, so I could rename the > screen shot files with the command: > > rename 's/ /_/g' Screen* > > Script follows: > > #!/usr/bin/perl > # > # rename > # > # perl script to rename files > # > # Usage: > # > # rename perlexpr [files] > # > > ($op = shift) || > die > "Usage: rename perlexpr [filenames] > where perlexpr is any perl expression that modifies \$\_: > 's/old/new/' > '\$\_ .= \".ext\"' > 'tr[A-Z][a-z]'\n"; > > if( !@ARGV ) { > @ARGV = <STDIN>; > chop( @ARGV ); > } > for( @ARGV ) { > $was = $_; > eval $op; > die $@ if $@; > rename($was,$_) unless $was eq $_; > } You guys are both over my head. I was hoping there was on OS X hack that would replace the saved Screen shots with _ rather than a space. I don't know or do Perl. I thought that was a beer.
From: Wes Groleau on 29 Jul 2010 22:28
On 07-29-2010 20:57, aRKay wrote: > Jim Gibson<jimsgibson(a)gmail.com> wrote: >> [snip] >> >> Script follows: >> >> #!/usr/bin/perl >> # >> # rename >> # >> # perl script to rename files >> # >> # Usage: >> # >> # rename perlexpr [files] >> # >> >> ($op = shift) || >> die >> "Usage: rename perlexpr [filenames] >> where perlexpr is any perl expression that modifies \$\_: >> 's/old/new/' >> '\$\_ .= \".ext\"' >> 'tr[A-Z][a-z]'\n"; >> >> if( !@ARGV ) { >> @ARGV =<STDIN>; >> chop( @ARGV ); >> } >> for( @ARGV ) { >> $was = $_; >> eval $op; >> die $@ if $@; >> rename($was,$_) unless $was eq $_; >> } > > You guys are both over my head. I was hoping there was on OS X hack > that would replace the saved Screen shots with _ rather than a space. Use TextEdit or something similar to create a file. Make the _first_ line the #!/usr/bin/perl from Jim's script (right after "Script follows") continue copying to the very last } in Jim's post. Save as whatever name makes sense to you in the directory with the screen shots. I would use Rename_Screen_Shots In Terminal, figure out how to get into the directory with the screen shots and the new file, then make the file executable with chmod a+x Rename_Screen_Shots Then run the file with this command: ls Screen* | Rename_Screen_Shots -- Wes Groleau Guidelines for judging others: 1. Don't attribute to malice that which can be adequately explained by stupidity. 2. Don't attribute to stupidity that which can be adequately explained by ignorance. 3. Don't attribute to ignorance that which can be adequately explained by misunderstanding. |