Date and Time

Insert date or time or both in to a file name
I would find it very usfull to be able to automate the prosseses of inserting the date ( in year mouth day order ) and the time in to a file name. This would allow the tracking of email saved as text in a sequential order. ie the file name would read subject date time. Is there a way of doing this with apple script ? I can not find any " get current date" or "get current time" comand. Is it posible to use apple script to open a sutable application and get the date and time from there ? anybody solved this ?

MacBookPro G4 server, Mac OS X (10.4.7)

Posted on May 1, 2007 12:47 PM

Reply
3 replies

May 1, 2007 3:04 PM in response to Chris Hey

Is it the current date you want?

There are example AppleScripts in /Applications/AppleScript/Example Scripts. Under the subfolder Info Scripts is one that shows how to get date and time. Under the subfolder Finder Scripts are a number of rename scripts, including "Add to File Names".

Probably there are ways to change the format using the AppleScript current date command, but the shell command date is particularly flexible. For example, try this AppleScript:

set the time_stamp to (do shell script "date +%Y%m%d-%H%M%S")
display dialog time_stamp

Replace the "display dialog" line with code to change the file names. If you can read Unix man pages, see man date and man strftime for details on formating the date command.




May 9, 2007 3:02 PM in response to Jeffrey Jones2

Yes thanks this does it

set the date_stamp to ((do shell script "date +%Y%m%d%H%M%S"))
set the clipboard to the date_stamp

I have then put this at the to of my apple scripts and then by selecting it, it runs and I paste it into the file name.

It would be good if you could have a quick key for the script but this does not seem to be a option in apple script ?

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.

Date and Time

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