shell script inside applescript no longer works as it used to

set Date to (do shell script "date ''+%Y-%m-%d-%H-%M-%S''")
return Date

this used to work, but now it won’t compile, is it cause I changed to lion? (The applescript seems to interpret the last few letters as a chinese character.) The shell script works in the terminal. The error message says “access not allowed”.

I got that access error msg in 10.5 as well when I pasted your example into Script Editor. However, this worked:

set TimeStamp to do shell script “date -n +%Y-%m-%d” → “2012-02-22”

Thank you! Writing it the way you did works for me too. I copy pasted the first one so once the original solution didn’t work I was lost.

This is what works:

set TimeStamp to do shell script "date -n +%Y-%m-%d-%H-%M-%S"

(I still have no idea what caused this. I’m sure that script was working in applescript and it does work in terminal.)

“Date” is a reserved word in AppleScript, and should not be used as a variable name. I have only vague ideas why your old code used to work, and now fails, so I won’t try to put them into words…

As Alastor says, date is a reserved word for Applescript.

But if you change your original script to this it works for me in Lion (10.7.3):

set theDate to (do shell script "date ''+%Y-%m-%d-%H-%M-%S''")
return theDate