Making folders for one month

Hello hello,

I would like to make all my dayfolders in the beginning of the month. This is possible i think...
(Normaly we make a folder in the beginning of a day.)

When i select choose folder I would like the script to make for every day of the month a folder... For example:
JANUARY (this folder i will make and choose)
2006-01-01
2006-01-02
2006-01-03
2006-01-04
...all days of this month.

it would be great if the script also count the month..
30 or 31 or 28 days... don't know if this is possible with applescript.

and is this possible?

G5 dual X - OS 10.3.9// G4 dual MAC OS 9 - OS 10.3.9 // G5 server - OS 10.3.9, Mac OS X (10.3.9), 2X1,5 Ghz Ram - 2x22 inch Lacie + G4 LAcie OS 9 -19 inch + Mini mac OS X 10.3.9

Posted on May 19, 2006 4:27 AM

Reply
13 replies

May 19, 2006 4:45 AM in response to Colin @ mac.com

Here's a very basic example of how you could write your script…

click here to open this script in your editor <pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:400px">tell application "Finder"
set target_folder to target of front Finder window
repeat with x from 1 to 31
if x < 10 then set x to "0" & x
make new folder at target_folder with properties {name:"2006-01-" & x}
end repeat
end tell</pre>This will generate the folders inside the folder of the frontmost Finder window. Note that the month "2006-01-" is hardcoded, as well as the number of days, 31.

May 19, 2006 5:58 PM in response to Colin @ mac.com

This expand from what Michael has, it'll check for all valid dates:

repeat with y from 1 to 12
if y < 10 then set y to "0" & y
repeat with x from 1 to 31
if x < 10 then set x to "0" & x
try
set the_date to (y & "-" & x & "-2006") as string
date the_date
make new folder at target_folder with properties {name:"2006-" & y & "-" & x}
on error
exit repeat
end try
end repeat
end repeat

May 20, 2006 11:48 AM in response to Colin @ mac.com

Colin,

Just curious why you wouldn't want to use iCal to create a work calendar and set up events that call an AppleScript or Automator action that creates a folder.

This would give you much more flexibility. You could control whether you want it everyday or just Mon-Fri, not on holidays, automatically produce them for the right number of days/month, and know when it was a leap year.

May 22, 2006 4:38 PM in response to Colin @ mac.com

Colin,
Why not have cron make the folder early each morning for you?
Here is the unix command to make the folder with todays date at Users/Shared:

mkdir /Users/Shared/`date "+20%y-%m-%d"`

This way you don't have to count days of the month or have a big stack of unused folders. Sort by name and today's is always at the end of the list.

(Note: the man pages says that 'c' should make note the year with century, as in 2006 instead of 06, but it did not work for me so I used 20. So write me a nasty note in 94 years.)
(Also note the tic mark is not a single quote, it's the key above the Tab key.)

Reese

May 23, 2006 2:43 AM in response to reese_

Hello Reese,

This is indeed the best solution for me aldo I can't get it working. Wen i run applescript I get a fault + 20%y-%m-%d"`
.

I also Have to use an other location such as
"HD Server Data 1:DATABASES:2BPRINTED: xx:xx:x:x:"
Do I have to replace the : with the /?

I would like to use this script to make 2 directories every day in the main db folders we use. and this with cronnix.
If you speak about cron... Is this cronnix too or something from apple?

Thanks in advance.. Still learning... Can you explain a bit more?

May 23, 2006 8:28 AM in response to Colin @ mac.com

Colin,
CrinniX is a GUI to configure cron. Corn is the Unix daemon which executes scheduled tasks. A daemon is a process which hangs around in the background waiting for something reason to activate, like a scheduled event in the case of cron.
In the "Command" box Cronnix is looking for a unix command (putting AppleScript would be another conversation).
Is HD Server Data 1 a local disk or a mounted server?
If it is a local disk then the Unix command will look like this:

mkdir -p "/DATABASES/2BPRINTED/"`date "+%Y-%m-%d"`

If it is a mounted server then it will look like this:

mkdir -p "/Volumes/HD Server Data 1/DATABASES/2BPRINTED/"`date "+%Y-%m-%d"`

If it is a mounted sever talk to your Admin about running this command on the server so that it runs even when the client is on vacation.

Note the -p after the mkdir. This will make all of the parent directories in the path even if they do not exist.

You can test the command by opening Terminal (in App/Utilities) and paste the command in at the prompt. If it works then the Terminal will act like nothing happened. It will only comment in the case of an error.

Reese

--Mark thanks for the Y tip.

May 24, 2006 8:44 AM in response to Colin @ mac.com

Colin,
Sure. One of the really cool things Apple did was provide a way to integrate AS and shell scripts.
Put this line in a Script Editor doc and save as an application:
do shell script "mkdir -p \"/DATABASES/2BPRINTED/\"`date \"+%Y-%m-%d\"`"

The forward slashes (\) tell AppleScript to ignore the following quote marks. (Officially known as escaping a special character.)

Reese

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Making folders for one month

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.