Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

create a folder or file with the DATE as name?

I am finalizing a backup routine that involves a couple of Time Machine backups, a couple of Clones (backs up once a week or once a month) and a couple of "manual" backups that I store off-site.


Right now I have a txt file that I keep in my Home Folder with a underscore so that it shows up at the top of my Home Folder where I manually change the date so I can check that I have a current backup and/or I can know how current the backup is ("_20111126.txt" for today). Right now, between the Time Machine, the Clones and the "regular" backups I am not sure how to do this really easy in any other way.


Today I realized that I would find it uber helpful to have a file that did this in an automated manner every day since I got into Time Machine to check this backup and the file is the same name for weeks at a time since I rarely change it.


Is there a way to do this in an automated manner or in a way that is as visually immediate as this method?


TIA for any help.

Posted on Nov 26, 2011 5:36 PM

Reply
Question marked as Best reply

Posted on Nov 26, 2011 5:43 PM

Open the Script Editor or AppleScript Editor and paste in:


tell application "Finder"

set the_date to current date

make folder at window 1 with properties {name:year of the_date & (month of the_date as number) & day of the_date as string}

end tell


If desired, save it as an application and put that application in the Dock.


(61840)

16 replies
Question marked as Best reply

Nov 26, 2011 5:43 PM in response to hotwheels22

Open the Script Editor or AppleScript Editor and paste in:


tell application "Finder"

set the_date to current date

make folder at window 1 with properties {name:year of the_date & (month of the_date as number) & day of the_date as string}

end tell


If desired, save it as an application and put that application in the Dock.


(61840)

Nov 27, 2011 6:10 PM in response to hotwheels22

hi niel.


sorry and thanks.


i think i see that the script is creating a folder with the year month and date in whatever folder i currently have when i run the script?


will this automatically get updated due to the fact that it is a script is that right?


also, is there a way to add an "-" or a "_" so that it shows up at the top of my Finder view? I tried a test or two with this but I am not sure I understand the code being used here.


- Jon

Jan 8, 2012 6:31 PM in response to Niel

hi niel.


can i please follow up with you on this one or alternatively ask if i should repost it.


i see here that you indicated that i can save this as an application (out of applescript I assume) and save it to the dock.


two things:


1. if i don't do this is the script still in applescript or on my hard drive somewhere or is this a one time operation/

2. is it possible to create a folder or a file with a date in this manner - but one which will automatically update itself to the current date automatically?! is see that this worked but it means that I am always forgetting to update this file and when i see it in the hard drive i am verifying has current data i am always having to go back out and update it and run the backup script again...


thanks!

Jan 8, 2012 10:08 PM in response to fane_j

hi. thanks very much. that looks like a helpful link.


do you happen to know if the script described should be updating the folder with a new date every day? if not. do you happen to know if it is possible to do this? i need to have a folder or file that will have the current date so i can see that the archives are updated in an easy way and this seems like a quick and easy way for me to do this if it will auto update.


thanks!

Jan 8, 2012 10:59 PM in response to hotwheels22

hotwheels 22 wrote:


if the script described should be updating the folder with a new date every day?

No. The name is static.

do you happen to know if it is possible to do this?

Yes. You can have a script which changes the name of an item to the current date, and which runs daily, using chron or iCal. Whether that's the best way to achieve whatever you're trying to achieve, well…

Jan 9, 2012 7:12 AM in response to fane_j

hi fj.


thanks very much.


can you help me here with your answer?


i just want to have a file or a folder that always has the current date in the name so that when i see it in my documents or desktop on the backup i know that the backup ran successfully. does this make sense?


i mean i thought that the script was doing this but i see it just does this in a static manner. are you saying that there is some method to do this with software called "Chron" or with iCal? Can you explain how this would be done if that is the case or what kind of name this sort of functionality would be described under?


Thanks!

Jan 9, 2012 8:23 AM in response to hotwheels22

hotwheels 22 wrote:


i just want to have a file or a folder that always has the current date in the name so that when i see it in my documents or desktop on the backup i know that the backup ran successfully. does this make sense?

Not to me. What if the renaming script works, but the backup fails? What if the backup works, but the renaming script fails?


You should use a proper backup application. Such an application should keep a log and should provide proper notification of the results of the backup

are you saying that there is some method to do this with software called "Chron" or with iCal?

I'm saying that, if you want to run a script daily or on some specified date, the way to do it is with cron (without the h, sorry for the typo) or iCal.


In fact, Apple says that one should use launchd instead of cron, but cron is still supported. Cron jobs are set with crontab, and there are plenty of examples and instructions on how to use it, as well as some GUIs for it.


As to iCal, it's simply a matter of choosing to Run Script as an alarm for an event. (It's in the iCal help.)


Here

<http://superuser.com/questions/126907/how-can-i-get-a-script-to-run-every-day-on -mac-os-x>

you'll find a succinct discussion of cron, launchd, and iCal, and links to more info on accomplishing this task.

Jan 9, 2012 4:20 PM in response to hotwheels22

hotwheels 22 wrote:


looks like iCal is not the best tool for this but Cron would be set to run the Applescript

It's easier to set up iCal than cron, even with a GUI like Cronnix.

unfortunately all of this looks way over my head

As some guy from around here is supposed to have said, the first step is half the journey.

Jan 14, 2012 4:14 PM in response to fane_j

hi. thanks very much.


can i please ask you what is involved here in terms of doing something like this in iCal? are there terms i can search in iCal for this functionality since it seems weird to me that I can get iCal to drop a folder onto my hard drive in the documents folder and keep the folder name updated with the current date?


also, can i please ask you what i get in addition to the iCal functionality in Cron or Cronnix? I've heard the names before and if it is worth investing the time in learning the software I would like to do this.


thanks you for the great help.

Jan 14, 2012 5:23 PM in response to hotwheels22


hotwheels 22 wrote:


can i please ask you what is involved here in terms of doing something like this in iCal?


As I said above, "it's simply a matter of choosing to Run Script as an alarm for an event".

it seems weird to me that I can get iCal to drop a folder onto my hard drive

You can't get iCal to "drop a folder". All iCal does is run the script at the appointed date and time. It's AppleScript that does the dropping. iCal doesn't know (or care) what's in the script.

what i get in addition to the iCal functionality in Cron or Cronnix?

You don't get iCal functionality in cron.


Cron is Unix daemon which runs tasks at various dates and times as directed by files maintained with crontab. As the links I directed you to indicate, in SL it's been superseded by launchd, but it's still fully compatible, and it's much easier to find instructions on how to set it up, because it's been around for decades. Cronnix is a GUI for crontab. Cron and crontab manuals are available in Terminal, with the commands


$ man cron

$ man crontab


Once again, you'll find it easier to run a script with iCal than with cron.

Jan 14, 2012 9:03 PM in response to fane_j

hi. thanks. sorry for the learning curve over here.


so am i creating this thing in Applescript and telling it to access iCal by selecting "Run Script as an alarm for an event"? I mean, am I /altering/ this script provided by Niel by selecting a prompt to tell it to access iCal in order to get the folder name updated with the current date? i haven't operated these tools so having a better understanding would help a great deal. thank you


"Open the Script Editor or AppleScript Editor and paste in:


tell application "Finder"

set the_date to current date

make folder at window 1 with properties {name:year of the_date & (month of the_date as number) & day of the_date as string}

end tell.


If desired, save it as an application and put that application in the Dock."

Jan 15, 2012 3:28 AM in response to hotwheels22

hotwheels 22 wrote:


having a better understanding would help a great deal.

A better understanding comes with study. I've already suggested an intro to AppleScript. Apple provides a Mac tutorial


<http://www.apple.com/support/mac101/work/>


of which iCal is lesson 8


<http://support.apple.com/kb/HT2513>


As to this thread's specific question, read on. I still believe that the task is in no way useful for the purpose you've outlined, but, in the best traditions of Apple Support Communities, WYWIWYG.


You have to go through the following stages:


1 Write script.

2 Test script.

3 Create & test iCal event.

4 Finalise iCal event.


1 Write script


Below is a slightly modified version of the script kindly provided by Niel.


The_prefix inserts a blank space as the folder name's first character; this will place it first in alphabetical order. The_sep(arator) inserts a hyphen for clarity.


The script is slightly more complicated than it should be for easier copying.


(The script includes a handler (on myDateend myDate) used to create dates with leading zeros; various versions have been floating on the web since times immemorial.)


The script will fail if an item with that name already exists.


property the_prefix : space

property the_sep : "-"


on run

tell application "Finder"

set the_path to (path to documents folder from user domain)

set the_name to (the_prefix & item 1 of my myDate())

set the_name to (the_name & the_sep & item 2 of my myDate())

set the_name to (the_name & the_sep & item 3 of my myDate())

make folder at the_path with properties {name:the_name}

end tell

end run


on myDate()

set myYear to "" & year of (current date)

set myMth to text -2 thru -1 of ("0" & (month of (current date)) * 1)

set myDay to text -2 thru -1 of ("0" & day of (current date))

return {myYear, myMth, myDay}

end myDate


1.1 Copy the script from this post.


1.2 Open AppleScript Editor.


1.3 Paste the script in a new script document.


1.4 Click the Compile button, or choose Script > Compile. This will insure that there were no errors during copying.


1.5 Change the target path. Currently, the script creates the new folder in your Documents folder. Replace the text


path to documents folder from user domain


with the location where you want the folder created. This can be specified as


folder "x" of folder "y" of disk "z"


where x is a folder in y, which is a folder at the root level of z.


1.6 Click Compile again, and, if there are no errors, save it as script. A good location is <~/Library/Scripts>. For the purpose of this example, name it Folder-Date.scpt


2 Test script


2.1 Still in AppleScript Editor, run script by clicking the Run button or choosing Script > Run. Check if there are any errors and the folder has been created. If the folder has been created, trash it.


2.2 Quit AppleScript Editor.


3 Create & test iCal event


3.1 Open iCal. Go to Month view. The current day should already be selected.


3.2 Create a new event by double-clicking in the current day. Name it "Folder-Date".


3.3 Make "from" and "to" to current day and current time plus a few minutes (however long it takes you to accomplish steps 3.4–3.6).


3.4 In "alarm" choose "Run Script".


3.5 If you have no scripts defined in iCal, an Open dialogue will appear. (Otherwise, you'll have to choose Other… from the respective pop-up menu.) Navigate to and select Folder-Date.scpt.


3.6 Under the name of the script an item reading "15 minutes before" will appear. Double-click on the number "15". It will be selected. Type 0. The item now reads "0 minutes before"


3.7 Click Done.


3.8 Wait until the appointed time and check if the folder was created as expected. If not, review the procedure.


4 Finalise iCal event


4.1 Still in iCal, double-click on Folder-Date event to open it.


4.2 Click Edit.


4.3 In "from" and "to" enter the time of day when you wish to run this script.


4.4 In "repeat" choose "Every day". The "end" item should read "Never".


4.5 Click Done


You're done.


Note limitations of this method: the script will run only if,


(a) the Mac is powered on and awake at the due time, and,

(b) you are logged in.


If you have any further questions about the script, you should at least read an introduction to AppleScript first. You're likely to find the answers there already.

create a folder or file with the DATE as name?

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