– Retrieve the current month
set thisDate to current date
– The month property of a data object is a constant and needs to be coerced into a string
set thisMonth to month of thisDate as string
set paidBills to “Macintosh HD:Users:ipthomas:Documents:Finances:Paid bills:”
– Check for the existence of a folder named after the current month, create as needed
tell application “Finder”
if not (the folder thisMonth of paidBills exists) then
make new folder at paidBills with properties {name:thisMonth}
end if
Here is what I get,
tell current application
current date
date “Friday, August 5, 2005 12:51:34 AM”
“Can’t make "August" into type integer.”
Why would it attempt to make this value into an integer?
class of paidBills is string and not a reference. Coerce the string to reference:
– Retrieve the current month
set thisDate to current date
– The month property of a data object is a constant and needs to be coerced into a string
set thisMonth to month of thisDate as string
try
set paidBills to “Macintosh HD:Users:ipthomas:Documents:Finances:Paid bills:” as alias
on error – folder “Paid bills” doesn’t exists
return
end try
– Check for the existence of a folder named after the current month, create as needed
tell application “Finder”
if not (the folder thisMonth of paidBills exists) then
make new folder at paidBills with properties {name:thisMonth}
end if
end tell
Thanks for the quick reply. I did some more reading in AppleScript: The Definitive Guide, and changed the code to this,
– Retrieve the current month
set thisDate to current date
– The month property of a date object is a constant and needs to be coerced into a string
set thisMonth to month of thisDate as string
– Check for the existence of a folder named after the current month, create as needed
tell application “Finder”
– Returns a reference to the folder (like file handle in Perl)
set paidBills to a reference to folder “Macintosh HD:Users:ipthomas:Documents:Finances:Paid bills:”
if not (the folder thisMonth of paidBills exists) then
make new folder at paidBills with properties {name:thisMonth}
end if
Earlier I had tried set paidBills to a reference to the folder, but I had done this outside of the tell block. The reference returned by the Finder’s dictionary is different than the reference returned by AppleScript in general. Thanks again.
What Finder needs is an object - rather than just a string, Ian. References are a way to identify objects within applications. They describe the type (or class) of object you’re looking for, where to look for the object, and how to distinguish the target object from other objects of the same type.
In fact, you shouldn’t really need the term “a reference to” here at all - as long as you tell Finder what type of object a given path refers to. In other words, your original script should have worked if (in the Finder tell block) you simply confirmed that ‘paidBills’ was a folder. And in your revised version, you could just say:
Here’s another way to put it all:
set thisMonth to (current date)'s month as string
tell application "Finder" to tell folder "Macintosh HD:Users:ipthomas:Documents:Finances:Paid bills:" to ¬
if not (exists folder thisMonth) then make new folder at it with properties {name:thisMonth}