Skip to content

Instantly share code, notes, and snippets.

@hitzhangjie
Last active February 9, 2019 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hitzhangjie/7808b6cf9d3143ae790ca9d70f047018 to your computer and use it in GitHub Desktop.
Save hitzhangjie/7808b6cf9d3143ae790ca9d70f047018 to your computer and use it in GitHub Desktop.
Create event in Calendar
set theQuery to "{query}"
-- 今天的开始、结束,用于筛选今天的事件列表
set todayStart to (current date)
set time of todayStart to 0
copy todayStart to todayEnd
set time of todayEnd to 86400
todayEnd
-- 待添加事件的开始、结束时间,我喜欢按照时间顺序追加的添加方式
copy todayStart to todoStart
set hours of todoStart to 8
set minutes of todoStart to 0
set seconds of todoStart to 0
-- 启动Calendar筛选今天内添加的todo事件列表
tell application "Calendar"
tell calendar "todo"
-- 遍历todo事件列表找到最后添加的事件
set allEvents to (every event where its start date is greater than or equal to todayStart and end date is less than todayEnd)
repeat with e in allEvents
set t to start date of e
if t ≥ todoStart then
copy t to todoStart
end if
end repeat
-- 继续追加新todo事件
set todoStart to todoStart + (1 * hours)
set todoEnd to todoStart + (1 * hours)
make new event with properties {summary:theQuery, start date:todoStart, end date:todoEnd}
end tell
-- 启动Calendar显示
if not running then
run
delay 0.25
end if
activate
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment