Go Back   The macosxhints Forums > OS X Help Requests > Applications



Reply
 
Thread Tools Rate Thread Display Modes
Old 02-20-2009, 02:31 AM   #1
marcojx
Prospect
 
Join Date: May 2008
Posts: 5
Automator to create sequential numbered file but not at the same time

Hello,

I have a folder where I create quite regularly a file from a template.
I explain : I have a folder name "2009" (for the current year) and inside this folder a folder named "Template" where I store my templates (I have several).
I then need to create in the 2009 folder files by duplicating one of the template, and name it "File_name_001". The next time I perform the action I want the next file to be named "File_name_002" and so on.
I tried to use the rename sequentially action from automator but it does not look for already existing files...
Also I did not find an action that would allow me to count filtered files, deduce a number and use this number to create the new file name.
Is there a way to do this ?
thanks

Marc
marcojx is offline   Reply With Quote
Old 02-20-2009, 07:22 PM   #2
tw
Hall of Famer
 
Join Date: Apr 2007
Posts: 4,262
automator is not going to do this for you. your best bet is to write an applescript that handles.
__________________
Philosophy is a battle against the bewitchment of our intelligence by means of language. -LW-
tw is offline   Reply With Quote
Old 02-20-2009, 09:20 PM   #3
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,415
I wrote a Perl script for you that will supply the name of the next file:
http://hayne.net/MacDev/Perl/nextFilename

To use it, you supply the name of the first file in the sequence (and optionally the name of the folder where the files are).
For example, if the current directory (folder) currently has files:
foo_001.txt, foo_002.txt, foo_003.txt
then running the command:
nextFilename "foo_001.txt"
will output "foo_004.txt" (without the quotes).

To get it to look at a specified folder, supply the path to the folder as the second command-line argument. For example:
nextFilename "foo_001.txt" ~/MyStuff/Reports

You can run a script like this from AppleScript via the 'do shell script' command
- see the AppleScript section of this Unix FAQ

Note that the above Perl script handles other sequence patterns as well - e.g. "report001_abc.txt"
- the only requirement is that there is a number somewhere in the filename.
__________________
hayne.net/macosx.html

Last edited by hayne; 02-20-2009 at 09:23 PM.
hayne is online now   Reply With Quote
Old 02-21-2009, 02:41 AM   #4
marcojx
Prospect
 
Join Date: May 2008
Posts: 5
thanks a lot !

I will study how to run it with applescript (though I can run it command line I think, I have some basic notions of unix).

It seems that I would need to go into applescript or similar as I have other tasks to automate.

Marc
marcojx is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 04:12 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.