why can't I change a date's time in Applescript?

I’ve got an Applescript for InDesign CS6 on Mountain Lion and the simplest task of setting a date’s time seems to no longer work. I can create a new date object (d) initialized with the current date, change each value

set d to current date --works fine
set month of d to tempMonth --works fine
set day of d to tempDay --works fine
set year of d to “20” & tempPubYear --works fine
set dayOfWeek to weekday of d --works fine
set time of d to 0 --ERROR

It used to work in earlier versions of InDesign/Mac OS X but now that last line shows up as an error. What is going on? I checked d and my variables and all are showing what they should be showing, except that darn time won’t change to zero.

Hi,

I’m using this for years to reset the time portion of a date


tell (current date) to set d to it - (its time)

It should still work. What error are you getting?

Hi,

It’s working for me also:

set d to current date --works fine
set month of d to 1 --works fine
set day of d to 1 --works fine
set year of d to "20" & "12" --works fine
set dayOfWeek to weekday of d --works fine
set time of d to 0 -- NO ERROR
d
--> date "Sunday, January 1, 2012 12:00:00 AM"

Maybe take it out of the Indesign tell block?

gl,
kel

Stack overflow.

And taking it out of the tell block changes the error message to “Adobe InDesign CS6 got an error: Can’t set time of date “Monday, October 14, 2013 4:21:50 PM” to 0.”

Try putting vertical bars around ‘time’. That’s just a guess without thinking.

Edited: no disregard. Vertical bars is to create a variable.

According to the error, you should be able to set the time of the ‘date’ to 0 out of the tell block.

gl,
kel

As a workaround, you could use:

set cur_date to (current date)
set date_string to date string of cur_date
set last_midnight to date date_string

until you find out what’s wrong.

gl,
kel

Hello.

Clearly a kludge, but this ought to work!

set dt to (current date)

tell dt
	set {its hours, its minutes, its seconds} to {0, 0, 0}
end tell