gpt4 book ai didi

macos - 将 iCal 事件导出到 osx 上的 .ics 文件

转载 作者:行者123 更新时间:2023-12-03 16:43:11 24 4
gpt4 key购买 nike

我需要创建将所有 iCal 事件导出到 isc 文件的应用程序。您能给我建议吗?使用 Cocoa 应用程序、命令行工具或 AppleScript 应用程序?...我正在尝试使用 AppleScript 应用程序,使用 CalendarStore 框架来执行此操作。我能够获取所有事件,但如何将它们保存到 ics 文件?

这是我的代码:

    - (IBAction)btnSelector:(id)sender {
CalCalendarStore *calendarStore = [CalCalendarStore defaultCalendarStore];
NSDate *startDate=[[NSDate alloc] init];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
startDate=[formatter dateFromString:@"2010-01-01 00:00:00"];
NSDate *endDate=[[NSDate alloc] init];
endDate=[formatter dateFromString:@"2050-01-01 00:00:00"];

NSArray *calendars = [calendarStore calendars];
NSPredicate *allEventsPredicate = [CalCalendarStore eventPredicateWithStartDate:startDate endDate:endDate calendars:[calendarStore calendars]];

NSArray *events = [calendarStore eventsWithPredicate:allEventsPredicate];

for(CalEvent *event in events)
{
//here i must save event to file...
NSLog(@"%@",event);
}

for (CalCalendar *calendar in calendars) {

self.lblNotification.title=[NSString stringWithFormat:@"%@ %@",self.lblNotification.title,calendar.title];

}

}

最佳答案

我采用了不同的方法 - 我使用 GUI 脚本从 Apple 日历应用程序导出指定数量的日历。它要么导出到桌面,要么导出到文档文件夹,我可能可以编辑脚本以强制它导出到桌面文件夹。

https://github.com/chinwayland/applescripts/blob/master/wintec-scripts/Export%20Calendars%20to%20ICS.applescript

-- This script exports multiple calendars to ICS one by one using GUI Scripting

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

set numberOfCalendars to display dialog "How many calendars?" default answer ""

tell application "Calendar"
activate
end tell

tell application "System Events"
tell process "Calendar"
repeat with i from 2 to text returned of numberOfCalendars as number

# Select each calendar
tell row i of outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of window 1
set selected to true
delay 1
end tell

# Click Export from Menu
tell menu item 1 of menu of menu item "Export" of menu "File" of menu bar 1
click
delay 3
end tell

# Click Export Button from pop up window
tell button "Export" of sheet 1 of window 1
click
delay 1
end tell


if button "Replace" of sheet 1 of sheet 1 of window 1 exists then
tell button "Replace" of sheet 1 of sheet 1 of window 1
click
end tell
delay 1
end if
end repeat
end tell
end tell

关于macos - 将 iCal 事件导出到 osx 上的 .ics 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11575347/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com