It just isn't working! Naming something with the current dateI.

Hello.

I have tried so meny variations upon this script, but nothing works. I see abosultely nothing wrong with this deroplet:


on open some_items
	set thedate to get short date string of (current date) as string
	set filename of some_items to (thedate) 
end open

I want it so that whatever you drop onto it, gets renamed to the current date. At the moment, it runs, and then simply tells me it cannot change the name to what I’ve asked it to be.

Can anyone spot any problems with this?

Thanks.

Lambo:

Try this:


on open some_items
	set thedate to get short date string of (current date) as string
	tell application "Finder" to set some_items's name to thedate
end open

Your first clue should have been the rendering of the term [filename] in your Script Editor. It should have been the same color as [thedate] and [some_items], indicating that it is a variable, not a property. When you see that, look around a little more for the correct property, in this case, [name].

Also remember that only the Finder can change the name of any file or folder, so you need to use a Finder tell command to make it happen.

Good luck,

eek! I tried your suggestion, and got the same error-message as before:

"Can’t set name of {alias “Macintosh HD:Users:joelamb:Desktop:Folder to rename:”} to “1/2/06”

That worried me somewhat, because of the “alias” bit. I’ve tried it with loads of stuff, and each time it is an alias, no matter what I try to rename. Could that have something to do with it?

Did this script work for you, on your 'puter?

Any help will be greatly appreciated.

Lambo

Model: ibook G4
AppleScript: 1.10.3
Browser: Safari 417.8
Operating System: Mac OS X (10.4)

Hi, Lambo.

The parameter of an ‘open’ handler (your variable ‘some_items’) is an AppleScript list containing the aliases of all the items dropped onto the droplet. Even if there’s only one item, ‘some_items’ is still a list and so doesn’t have a ‘name’ property. You want to set the name of the item it contains:

on open some_items
	set thedate to short date string of (current date)
	tell application "Finder" to set name of item 1 of some_items to thedate
end open

Ideally, you’d also include some code to check that only one item has been dropped on the droplet. :slight_smile:

on open some_items
	if ((count some_items) is 1) then
		set thedate to short date string of (current date)
		tell application "Finder" to set name of item 1 of some_items to thedate
	else
		display dialog "This droplet only accepts one item at a time!" buttons {"OK"} default button 1 with icon stop
	end if
end open

Thank you very much! Works perfectly. :smiley: