我在 Automator 上编写了一个 AppleScript,其目标是
当我尝试在约会日期/时间中添加小时数时,脚本可以工作,但失败。由于我所在的时区,我需要将事件提前 +6 小时。
样本数据:
4/29/24 - 2:30pm-3:30pm - XYASHDK
4/29/24 - 6:30pm-9:30pm - DLHEOSH
Apple 脚本:
{在 Automator 上, 带有上述数据的“获取指定文本”后面是 “从文本中提取日期”后跟此脚本}
on run {input, parameters}
set apptList to input
repeat with i from 1 to count of apptList
set appt to item i of apptList
set AppleScript's text item delimiters to " - "
set stringItems to text items of appt
set apptDate to item 1 of stringItems
set AppleScript's text item delimiters to ""
set apptTimes to item 2 of stringItems
set AppleScript's text item delimiters to "-"
set hoursItems to text items of apptTimes
set apptBegTime to item 1 of hoursItems
set apptEndTime to item 2 of hoursItems
set apptBegin to date (apptDate & " " & apptBegTime)
set apptEnd to date (apptDate & " " & apptEndTime)
set apptBeginTZ to ((hours of apptBegin) + 6)
set apptEndTZ to ((hours of apptEnd) + 6)
tell application "Calendar"
tell calendar "ABC"
make new event with properties {summary:"busy", start date:apptBeginTZ, end date:apptEndTZ}
end tell
end tell
end repeat
end run
如上所述,我尝试将 N 小时添加到最终预约时间,但出现以下错误:
“运行 AppleScript”操作遇到错误:“日历有一个 错误:无法将 8 转换为日期类型。”
您对如何完成将预约时间增加 N 小时有什么建议吗?
AppleScript 日期的最小单位是
second
,您可以用秒甚至小时进行数据数学计算,因此语法几乎是“自然人类”
set apptBeginTZ to apptBegin + 6 * hours
set apptEndTZ to apptEnd + 6 * hours