You're creating an Ant build script, and you need to determine the operating system the script is running on, so you can make conditional decisions within the build script. You typically want/need to do this if you're going to run tasks/targets that are different for each operating system (Mac, Windows, Unix, etc.).
A frequently asked Java question is, "How can I tell what version of Java is running my program?"
Answer: Just use this line of source code to determine the version of Java that is running your program:
Java Mac FAQ: How can I determine whether my Java/Swing application is running on Mac OS X, or some other operating system?
Here's the test I use to determine whether my Java application is running on Mac OS X:
Perl file test FAQ: How can I run a Perl test to see if I have read access on a file?
Using Perl it's very simple to determine whether you can read a file. Just use the
-r file operator, as shown in this example:
If you ever need to determine what directory your Java code is being run from (essentially the current working directory), you can get this information from the system properties, specifically the
The following line of Java code shows how to determine what directory your Java application was started in. This information is stored in the
user.dir system property, which you access like this:
A quick note about getting the current time in AppleScript in two different formats. This command
set t to (time string of (current date))
yields something like this result (depending on the time of day):
but this command
set t to (time of (current date))
yields something like this result:
(That's the number of seconds since midnight, in case you were wondering.)