我正在尝试创建一个applescript脚本,它将以以下形式获取日期:
02/20/99
然后,从日期中减去5天,返回如下日期:
02/15/99
这是我的基本applescript,但是,很明显,我缺少将日期转换为我可以操作的东西(并将其返回为人类可读的东西)的逻辑。
set itemPath to quoted form of POSIX path of theFile
set dateString to do shell script "awk 'NR == 10 {print $3}' " & itemPath & " -"
set myDueDate to dateString - (5 * days)
set theTask to "Pay AMEX bill"
tell application "OmniFocus"
tell front document
set theContext to first flattened context where its name = "OFFICE"
set theProject to first flattened context where its name = "Bookkeeping - PMS"
tell theProject to make new task with properties {name:theTask, context:theContext, due date:myDueDate}
end tell
end tell
提前感谢!
我想这几行应该足够满足你的需要了:
set dateString to "02/20/99"
set thisDate to date dateString
set fiveDaysEarlier to thisDate - 5 * days
log date string of fiveDaysEarlier
log short date string of fiveDaysEarlier
本页有一些在将字符串转换为date类对象时支持的强制转换的示例:AppleScript类引用:date
此外,这可能是不言而喻的,但是字符串"02/20/99"不符合千年虫标准,所以必须在某个地方猜测这个日期位于哪个世纪。
如果你得到错误"FileMaker Pro得到一个错误:Object not found. number -1728,添加我的before date。例如,
设置thisDate为我的日期。
当在tell内部工作时,我认为它需要访问tell作用域之外的方法