AppleScript 将 iCal 事件从一个日历移动到另一个日历

问题描述 投票:0回答:2

试图编写脚本将包含关键字的事件从一个日历移动到另一个日历但碰壁了。任何指针?我目前正在做这样的事情:

tell application "Calendar"
move ((events of calendar "Cal1") whose summary contains "Test") to calendar "Cal2" 
end tell

但是,这是 iCal 返回此错误:

“保存日历数据时出错。 日历在保存到数据库时遇到严重错误,最近的更改可能会丢失。控制台中可能会提供更多信息。”

我做错了什么?

谢谢:) J

calendar applescript icalendar
2个回答
0
投票

这对于当前版本的 Calendar 中的 AppleScript 来说是一项艰巨的任务。可以通过重复目标事件列表,根据目标事件的属性创建新事件,然后删除原始事件来完成。或者你可以从App Store获取我的应用程序。


0
投票

您不能使用日历移动命令移动多个事件,因为大多数事件的某些属性未初始化。解决方法是:您应该使用事件重复循环,检查属性是否已初始化,不要尝试复制未初始化的属性。

我为此任务使用以下脚本。照原样,脚本duplicates事件(按摘要条件)从一个日历到另一个。如果您想要 move 效果,请取消注释脚本底部的 3 行代码:

set SourceCalendarName to "Σπίτι"
set DestinationCalendarName to "Untitled"

tell application "Calendar"
    set sourceCalendar to calendar SourceCalendarName
    set destinationCalendar to calendar DestinationCalendarName
    
    -- Copy sources to destination --
    repeat with anEvent in (get events of sourceCalendar whose summary contains "hello")
        
        tell anEvent
            set |allday event| to allday event
            set |start date| to start date
            set |end date| to end date
            set |url| to url
            set |location| to location
            set |recurrence| to recurrence
            set |description| to description
            set |excluded dates| to excluded dates
            set |stamp date| to stamp date
            set |summary| to summary
        end tell
        
        tell destinationCalendar
            set newEvent to (make new event at end of events with properties {allday event:|allday event|, start date:|start date|, end date:|end date|})
            tell newEvent
                if not (|url| is missing value) then set url to |url|
                if not (|location| is missing value) then set location to |location|
                if not (|recurrence| is missing value) then set recurrence to |recurrence|
                if not (|description| is missing value) then set description to |description|
                if not (|summary| is missing value) then set summary to |summary|
                if not (|excluded dates| is missing value) then set excluded dates to |excluded dates|
                if not (|stamp date| is missing value) then set stamp date to |stamp date|
            end tell
        end tell
        
        -- try
        -- delete (contents of anEvent)
        -- end try
        
    end repeat
end tell
© www.soinside.com 2019 - 2024. All rights reserved.