newbie question: finder bug?

I’ve been trying to find out why the following script won’t work on OS X Finder:

tell app “Finder”
make new folder at insertion location
end tell

I believe this worked on OS 9 (or before).

I know, I can do the following to make it work:
set folderLoc to insertion location
make new folder at folderLoc

but I want to know if this is a bug or a feature and if there are any other such instances with OS X FInder.

Also is there any way smart way to get the number of year, month, date from current date?
right now, I am doing
set {theYr, theMt, theDy} to {year,month,day} of (current date)
but this of course would give me theMt=“June”
Instead of that, I I want to get theMt =6
I know I can coerce it like set theMtNum to theMt as number
but it would look smart if I can have one line which will get all three numbers out of current date.


As to part 2 of your query, there are tons of date formatting scripts around (try the search feature, the FAQ, Script Builders & Code Exchange) and NG and AK will be happy to chime in, I’m sure.

In regards to to part 1, AppleScript is usually very kind and adds some missing code for you (which is why the event log looks so much more verbose than your actual code) but sometimes it falls down on the job and you need to add the code that it fails to put in for you. In this case, it’s the word “get”:

Generally, if the Finder isn’t behaving the way you think it should, try adding the explicit “get” and chances are things will start to work more smoothly.


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

In reverse order…

The date question is easy.

Asking for 'month of (current date) will return the month name. However, AppleScript can coerce this to an integer for you:

month of (current date)
--> June
month of (current date) as integer
--> 6

On the folder creation question, I’ve never heard of ‘insertion location’ in respect to the Finder. In any case the following code works:

tell application "Finder"
	make new folder at (get insertion location)
end tell

The extra level of parentheses appears to resolve the problem

Only a note. This is only true under Panther (AS 1.9.2 and further).

As Camelot says - and if you have Panther - you can coerce the month to integer. If you’re desperate for it to “look smart” in one line, you could write it like this:

tell (current date) to set {theYr, theMt, theDy} to {year, its month as integer, day}

If your next question involves leading zeros or Jaguar, you’ll more than one line. :wink:

I’d never heard of the Finder’s ‘insertion location’ either - but there it is, large as life, in all my Finder dictionaries:

Learn something new every day! :slight_smile:

my ADSL was down for a few days and I couldn’t come back.
Thank you all for great advices.

I really like AppleScript but finding this nice community made me like it even more.

happy scripting!


You’ve also got (OS X, of course)

set dateString to (do shell script "date "+%D %T"")

and all its variations which can be viewed by

do shell script "man date"
  • Dan