Can a script create a folder and include in the folder name the current date??
I know this is getting a little complicated but I’m hoping someone out here will know.
Thanks in advance.
JT
Complicated? Nah.
set theDate to current date
set theDay to the day of theDate
set theMonth to the month of theDate
tell application "Finder"
make new folder at desktop with properties {name:"new folder " & theMonth & " " & theDay}
end tell
Dude, Your the MAN!!!
Trying it now.
get back to ya…
Thank you, thank you…
JT
Ok that was a easy one, just seeing if your paying attention…
No really thanks alot.
JT
: Ok that was a easy one, just seeing if your paying attention…
Thank goodness I passed!
: No really thanks alot.
Hey, no problemo. Glad to help.
And thanks for your participation.
T.J.
tj@macscripter.net
: add this to the top of the script, this will create a list of months
: property theMonths : {January, February, March, April, May, June,
: July, August, September, October, November, December}
: repeat with x from 1 to 12
: if theMonth = (item x of theMonths) then
: set theMonth to x
: exit repeat
:
: then use the rest of your code there.
: this is more simplified than all the if than else statements for the months
There’s also a neat formula for calculating the month number.
[url=http://homepage.mac.com/dlivesay/aclafaq.html#0203] http://homepage.mac.com/dlivesay/aclafaq.html#0203[/url]
set theDate to the current date --or any other date
--result is the number of the month of 'theDate'
copy theDate to b
set the month of b to January
set monthNum to (1 + (theDate - b + 1314864) div 2629728)
How do I refer to this newly created folder with the date stamped on it. I want to move a file into this folder, but don’t know how to reference it after it has been created. The folder name will change depending on what day it is. I was thinking of using a wildcard like “XYZ*” but that didn’t work.
make new folder at folder “ABC” with properties {name:" XYZ " & theMonth & " " & theDay}
Thanks in advance JT
: How do I refer to this newly created folder with the date stamped on it. I
: want to move a file into this folder, but don’t know how to reference it
: after it has been created. The folder name will change depending on what
: day it is. I was thinking of using a wildcard like “XYZ*” but
: that didn’t work.
: make new folder at folder “ABC” with properties {name:" XYZ
: " & theMonth & " " & theDay}
Try this:
set newTargetFolder to make new folder at folder “ABC” with properties {name:" XYZ " & theMonth & " " & theDay}
You should then be able to move the file to newTargetFolder.
– Rob J
: How do I refer to this newly created folder with the date stamped on it. I
: want to move a file into this folder, but don’t know how to reference it
: after it has been created. The folder name will change depending on what
: day it is. I was thinking of using a wildcard like “XYZ*” but
: that didn’t work.
: make new folder at folder “ABC” with properties {name:" XYZ
: " & theMonth & " " & theDay}
: Thanks in advance JT
Add the following line just after the “make new folder …” statement:[code:1:000]set NewFolderPath to result[/code:1:000]and use NewFolderPath while referring the newly created folder.
this will allow your users to name the folder, and it abbreviates the month.
on run
set theDate to current date
set theDay to the day of theDate
set theMonth to the month of theDate as string
set theYear to the year of theDate
set monthAb to characters 1 thru 3 of theMonth as string
set theReply to display dialog "Please input the folder name you wish to create:" default answer "" buttons {"Create", "Cancel"} default button "Create"
set theFolderName to text returned of theReply
tell application "Finder"
--make new folder at desktop with properties {name:"new folder " & theMonth & " " & theDay}
make new folder at desktop with properties {name:theFolderName & "_" & monthAb & "/" & theDay & "/" & theYear}
set NewFolderPath to result
end tell
display dialog NewFolderPath as string
end run
or this one also allows you to have the user specify where to save the file to:
on run
set theDate to current date
set theDay to the day of theDate
set theMonth to the month of theDate as string
set theYear to the year of theDate
set monthAb to characters 1 thru 3 of theMonth as string
set pathForFile to choose folder with prompt "Please select a Destination Folder."
set theReply to display dialog "Please input the folder name you wish to create:" default answer "" buttons {"Create", "Cancel"} default button "Create"
set theFolderName to text returned of theReply
tell application "Finder"
make new folder at pathForFile with properties {name:theFolderName & "_" & monthAb & "/" & theDay & "/" & theYear}
set NewFolderPath to result
end tell
display dialog NewFolderPath as string
end run
This is great stuff, Thanks alot.
Can I get the date to display as 02/01/02 Currently im using.
set theDate to current date set theDay to the day of the Date set the Month to the month of theDate
and then refering to it…
theMonth & the Day
This gives me February1 in the name of the created folder
I would like 02/01/02
Thanks in advance.
This would look the best for our situation.
Thanks in advance.
JT
property monthVar : "0"
on run
set theDate to current date
set theDay to the day of theDate
set theMonth to the month of theDate
set theYear to the year of theDate
set monthVar to theMonth
checkMonth()
set pathForFile to choose folder with prompt "Please select a Destination Folder."
set theReply to display dialog "Please input the folder name you wish to create:" default answer "" buttons {"Create", "Cancel"} default button "Create"
set theFolderName to text returned of theReply
tell application "Finder"
make new folder at pathForFile with properties {name:theFolderName & "_" & monthVar & "/" & theDay & "/" & theYear}
set NewFolderPath to result
end tell
display dialog NewFolderPath as string
end run
on checkMonth()
if monthVar = January then
set monthVar to "01"
else if monthVar = February then
set monthVar to "02"
else if monthVar = March then
set monthVar to "03"
else if monthVar = April then
set monthVar to "04"
else if monthVar = May then
set monthVar to "05"
else if monthVar = June then
set monthVar to "06"
else if monthVar = July then
set monthVar to "07"
else if monthVar = August then
set monthVar to "08"
else if monthVar = September then
set monthVar to "09"
else if monthVar = October then
set monthVar to "10"
else if monthVar = November then
set monthVar to "11"
else if monthVar = December then
set monthVar to "12"
end if
end checkMonth
Here is my current script
on adding folder items to theFolder after receiving theAddedItems
repeat with thisItem in theAddedItems
tell application “Finder”
set theDate to current date
set theDay to the day of theDate
set theMonth to the month of theDate
set thePrefix to “AG-RF_”
set itemName to name of thisItem
set newName to (thePrefix & itemName)
set name of thisItem to newName
if folder “Comp Images” of desktop exists then
set compImages to folder “Comp Images” of desktop
if folder ("Comp Images " & theMonth & theDay) of compImages exists then
move thisItem to folder ("Comp Images " & theMonth & theDay) of compImages
else
make new folder at compImages with properties {name:"Comp Images " & theMonth & theDay}
move thisItem to folder ("Comp Images " & theMonth & theDay) of compImages
end if
else
make new folder at desktop with properties {name:“Comp Images”}
set compImages to folder “Comp Images” of desktop
if folder ("Comp Images " & theMonth & theDay) of compImages exists then
move thisItem to folder ("Comp Images " & theMonth & theDay) of compImages
else
make new folder at compImages with properties {name:"Comp Images " & theMonth & theDay}
move thisItem to folder ("Comp Images " & theMonth & theDay) of compImages
end if
end if
end tell
end repeat end adding folder items to
This is working great, I tried to include parts of your date script but with no success. Keeping this script working how would I include the code so the date displays "foldername_02/01/02
Thanks JT
add this to the top of the script, this will create a list of months
property theMonths : {January, February, March, April, May, June, July, August, September, October, November, December}
: on adding folder items to theFolder after receiving theAddedItems
: repeat with thisItem in theAddedItems
: tell application “Finder”
: set theDate to current date
: set theDay to the day of theDate
: set theMonth to the month of theDate
repeat with x from 1 to 12
if theMonth = (item x of theMonths) then
set theMonth to x
exit repeat
then use the rest of your code there.
this is more simplified than all the if than else statements for the months
Hey Kirk, Sorry it took so long to reply, been real busy… this formula for the date works great, thanks for your help.
JT