0
votes

So I am new to applescript and I am trying to make an application that will make a new folder at the desktop that has the name of the current date and time. Every time I run it, there is and error and it reads, "Can’t make "11/8/13" into type number." Please help and thanks for your input and answers!

    tell application "Finder"
        set p to path to desktop
        set d to short date string of (current date)
        set t to time string of (current date)
        set FullDate to d + t
        make new folder at p with properties {name:FullDate}
    end tell
2

2 Answers

2
votes

You use & to concatenate in AppleScript, otherwise it thinks you are trying to add a number.

set p to path to desktop
set d to short date string of (current date)
set t to time string of (current date)
set FullDate to d & space & t

tell application "Finder" to make new folder at p with properties {name:FullDate}
0
votes

Following script makes (and opens) a new folder with format "YYYY-MM-DD". It makes the folder in the first finder window or, if none, on the desktop. It's easy to adjust.

tell application "Finder"
    try
        if exists Finder window 1 then
            set thisPath to (the target of the front window) as alias
        else
            set thisPath to (path to desktop)
        end if
    on error
        return
    end try
end tell
set x to my the_perfect_datestring()
if x is not "-ERROR" then
    set fullPath to thisPath & x as text
    tell application "Finder"
        try
            --activate
            if not (exists fullPath) then
                set y to make new folder at thisPath with properties {name:x}
            end if
            activate
            open y
        end try
    end tell
end if
on the_perfect_datestring()
    try
        set cd to (the current date)
        set the_year to year of (cd) as number
        set the_month to month of (cd) as number
        set the_day to day of (cd) as number
        if the_month < 10 then set the_month to "0" & the_month
        if the_day < 10 then set the_day to "0" & the_day
        return ((the_year & "-" & the_month & "-" & the_day) as string)
    on error
        return "-ERROR"
    end try
end the_perfect_datestring