AppleScript Overview


Author: David Hood
Contents Page - About AppleScript
Date Last Modified: 25th August 2003
E-mail: caversham@otago.ac.nz

Previous Page 2 of 2 Contents Page

For this particular example I wanted the computer to produce a time stamp and make it available anywhere, so I decided to use the clipboard. I could then paste the timestamp in where I happened to be.

I opened the screenshotScript Editor program and typed in two lines

set timestamp to (do shell script "date '+%y%m%d%H%M'")
set the clipboard to (timestamp as text)

The first line uses the do shell script command to get the timestamp from the OS X command line, and sets the variable 'timestamp' to the result. As this particular script uses the command line it will only work in OS X, to write an equivalent for OS 9 or earlier would use a different technique.

The second line sets the clipboard with the contents of the variable 'timestamp'. Because information sometimes needs to be in a particular form, in this case we need to explicitly set the contents of 'timestamp' to text.

I can run this from Script Editor, but as this script is intended as a convenience I save the script to the Scripts folder in the Library folder of my home directory. This lets me run the script from Script Editor at any time I like. I can then past the timestamp where I like.

Return to Contents Page