Skip to content

Commit 6f75af7

Browse files
committed
Choose the event closest to 'now' even if it's in the past
1 parent 58459a4 commit 6f75af7

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

Info.plist

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
<key>CFBundlePackageType</key>
1818
<string>BNDL</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>1.5.0</string>
20+
<string>1.5.1</string>
2121
<key>CFBundleVersion</key>
22-
<string>145</string>
22+
<string>146</string>
2323
<key>NSCalendarsUsageDescription</key>
2424
<string>Create and view calendar items from within Quicksilver</string>
2525
<key>NSPrincipalClass</key>
@@ -141,28 +141,28 @@
141141
<string>&lt;h2&gt;Calendar &amp;amp; Reminders Plugin&lt;/h2&gt;
142142
&lt;p&gt;This plugin adds actions for creating Calendar Events (Calendar.app) and Reminders (Reminders.app) from within Quicksilver&lt;/p&gt;
143143
&lt;h3&gt;Permissions&lt;/h3&gt;
144-
&lt;p&gt;This plugin requires access to your Calendar and Reminders. Make sure you have granted Quicksilver permissions by adding it to the &lt;a href="x-apple.systempreferences:com.apple.preference.security?Privacy_Calendars"&gt;Calendars list&lt;/a&gt; and &lt;a href="x-apple.systempreferences:com.apple.preference.security?Privacy_Reminders"&gt;Reminders list&lt;/a&gt; in the System Preferences.&lt;/p&gt;
144+
&lt;p&gt;This plugin requires access to your Calendar and Reminders. Make sure you have granted Quicksilver permissions by adding it to the &lt;a href=&quot;x-apple.systempreferences:com.apple.preference.security?Privacy_Calendars&quot;&gt;Calendars list&lt;/a&gt; and &lt;a href=&quot;x-apple.systempreferences:com.apple.preference.security?Privacy_Reminders&quot;&gt;Reminders list&lt;/a&gt; in the System Preferences.&lt;/p&gt;
145145
&lt;h3&gt;Actions&lt;/h3&gt;
146146
&lt;p&gt;&lt;strong&gt;Create Calendar Event&lt;/strong&gt;&lt;/p&gt;
147-
&lt;p&gt;This action takes text from Quicksilver's 1st pane, and adds it as an event to your selected Calendar in Quicksilver's 3rd pane.&lt;br&gt;
147+
&lt;p&gt;This action takes text from Quicksilver&apos;s 1st pane, and adds it as an event to your selected Calendar in Quicksilver&apos;s 3rd pane.&lt;br&gt;
148148
Examples of text could be &lt;code&gt;Dinner with Tom next Tuesday&lt;/code&gt; or &lt;code&gt;Visit mum at 3pm&lt;/code&gt;.&lt;/p&gt;
149149
&lt;p&gt;You can improve how an event displays in your Calendar by separating the name of the event and the time it takes place with two dashes &lt;code&gt;--&lt;/code&gt;&lt;br&gt;
150-
Using &lt;code&gt;Next Tuesday -- Dinner with Tom&lt;/code&gt; will create an event called just &lt;code&gt;Dinner with Tom&lt;/code&gt; in your calendar. Supported languages include English, Japanese, French, Dutch, Russian, English (UK) with partial support for German, Portuguese and Chinese, thanks to the &lt;a href="https://github.com/wanasit/chrono"&gt;Chrono project&lt;/a&gt;&lt;/p&gt;
150+
Using &lt;code&gt;Next Tuesday -- Dinner with Tom&lt;/code&gt; will create an event called just &lt;code&gt;Dinner with Tom&lt;/code&gt; in your calendar. Supported languages include English, Japanese, French, Dutch, Russian, English (UK) with partial support for German, Portuguese and Chinese, thanks to the &lt;a href=&quot;https://github.com/wanasit/chrono&quot;&gt;Chrono project&lt;/a&gt;&lt;/p&gt;
151151
&lt;p&gt;&lt;strong&gt;Create Reminder&lt;/strong&gt;&lt;/p&gt;
152-
&lt;p&gt;This action takes text from Quicksilver's 1st pane, and adds it as a Reminder to your selected Reminders List in Quicksilver's 3rd pane.&lt;/p&gt;
152+
&lt;p&gt;This action takes text from Quicksilver&apos;s 1st pane, and adds it as a Reminder to your selected Reminders List in Quicksilver&apos;s 3rd pane.&lt;/p&gt;
153153
&lt;p&gt;Examples of text could be &lt;code&gt;Do the shopping&lt;/code&gt; or &lt;code&gt;Pick up the kids from school&lt;/code&gt;.&lt;/p&gt;
154154
&lt;p&gt;You can set the priority of an event by prefixing your event with any number of exclamation marks &lt;code&gt;!&lt;/code&gt;&lt;br&gt;
155155
&lt;em&gt;One&lt;/em&gt; exclamantion mark gives the Reminder a &lt;em&gt;low&lt;/em&gt; priority, &lt;em&gt;two&lt;/em&gt; give the Reminder a &lt;em&gt;medium&lt;/em&gt; priority and &lt;em&gt;three&lt;/em&gt; gives it a &lt;em&gt;high&lt;/em&gt; priority.&lt;/p&gt;
156156
&lt;p&gt;&lt;code&gt;!! This is a medium priority reminder&lt;/code&gt;&lt;br&gt;
157157
&lt;code&gt;This reminder has no priority set&lt;/code&gt;&lt;/p&gt;
158158
&lt;h3&gt;Next Online Meeting Object&lt;/h3&gt;
159-
&lt;p&gt;This plugin adds a 'Next online meeting' object to your catalog. Use it to find an upcoming meeting (within the next 30 minutes) on your calendar. It will automatically retrieve the URL from the calendar information for you to open.&lt;/p&gt;
159+
&lt;p&gt;This plugin adds a &apos;Next online meeting&apos; object to your catalog. Use it to find an upcoming meeting (within the next 30 minutes) on your calendar. It will automatically retrieve the URL from the calendar information for you to open.&lt;/p&gt;
160160
&lt;h3&gt;Default Calendars for Events/Reminders&lt;/h3&gt;
161161
&lt;p&gt;You can select the default calendar for Events/Reminders by going to Preferences &amp;gt; Calendars in the Quicksilver preferences&lt;/p&gt;
162162
&lt;h3&gt;Open Source Licenses&lt;/h3&gt;
163163
&lt;p&gt;This project uses code from:
164-
* &lt;a href="https://github.com/wanasit/chrono/blob/master/LICENSE.txt"&gt;Chrono Project&lt;/a&gt;
165-
* &lt;a href="https://github.com/leits/MeetingBar/blob/master/LICENSE"&gt;Meeting Bar Project&lt;/a&gt;&lt;/p&gt;</string>
164+
* &lt;a href=&quot;https://github.com/wanasit/chrono/blob/master/LICENSE.txt&quot;&gt;Chrono Project&lt;/a&gt;
165+
* &lt;a href=&quot;https://github.com/leits/MeetingBar/blob/master/LICENSE&quot;&gt;Meeting Bar Project&lt;/a&gt;&lt;/p&gt;</string>
166166
<key>icon</key>
167167
<string>com.apple.iCal</string>
168168
<key>qsversion</key>

QSiCalModule.m

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ @implementation QSiCalModule
1919

2020
- (id)init {
2121
if (self = [super init]) {
22-
eventStore = [[EKEventStore alloc] initWithAccessToEntityTypes:(EKEntityMaskEvent | EKEntityMaskReminder)];
22+
eventStore = [[EKEventStore alloc] init];
2323
_eventsCalendars = nil;
2424
_remindersCalendars = nil;
2525
}
@@ -331,10 +331,10 @@ - (QSObject *)resolveProxyObject:(QSProxyObject *)proxy
331331
NSUInteger minutesForward = 30;
332332
NSUInteger interval = minutesForward * 60;
333333
NSDate *now = [NSDate date];
334-
NSDate *cutoff = [NSDate dateWithTimeIntervalSinceNow:interval];
334+
NSDate *cutoff = [now dateByAddingTimeInterval:interval];
335335
NSPredicate *query = [eventStore predicateForEventsWithStartDate:now endDate:cutoff calendars:nil];
336336
NSArray *events = [eventStore eventsMatchingPredicate:query];
337-
// pick the meeting event that hasn't started
337+
// pick the meeting event with a start date closest to 'now'
338338
EKEvent *targetEvent = nil;
339339
NSDictionary *targetData;
340340
for (EKEvent *upcomingEvent in events) {
@@ -343,14 +343,16 @@ - (QSObject *)resolveProxyObject:(QSProxyObject *)proxy
343343
// skip events with no meeting URL
344344
continue;
345345
}
346-
if ([[upcomingEvent startDate] compare:now] == NSOrderedDescending) {
346+
// find the event with the startDate closest to 'now'
347+
if (!targetEvent || (fabs([[upcomingEvent startDate] timeIntervalSinceDate:now]) < fabs([[targetEvent startDate] timeIntervalSinceDate:now]))) {
348+
// if it's an event in the past and it's already finished, ignore it
349+
if ([[upcomingEvent startDate] compare:now] == NSOrderedAscending && [[upcomingEvent endDate] compare:now] == NSOrderedAscending) {
350+
continue;
351+
}
347352
// prefer an event in the future
348353
targetData = meetingData;
349354
targetEvent = upcomingEvent;
350-
break;
351355
}
352-
targetData = meetingData;
353-
targetEvent = upcomingEvent;
354356
}
355357
if (targetEvent) {
356358
return objectFromEvent(targetEvent, targetData);

0 commit comments

Comments
 (0)