I found this https://macscripter.net/viewtopic.php?pid=165851#p165851
and tried to adjust to no avail. I get output, but not what I expected.
Here’s my altered code;
-- Ask the user for the range of dates to be covered.
on getDateRange()
set today to (current date)
set d1 to today's short date string
set d2 to short date string of (today + 6 * days)
set dateRange to text returned of (display dialog "Enter the required date range:" default answer d1 & " - " & d2)
set dateRangeStart to date (text from word 1 to word 3 of dateRange)
set dateRangeEnd to date (text from word -3 to word -1 of dateRange)
set dateRangeEnd's time to days - 1 -- Sets the last date's time to 23:59:59, the last second of the range.
return {dateRangeStart, dateRangeEnd}
end getDateRange
-- Return the start dates and summaries which are in the given date range.
on filterToDateRange(theStartDates, theLocations, dateRangeStart, dateRangeEnd)
set {eventDatesInRange, eventLocationsInRange} to {{}, {}}
repeat with i from 1 to (count theStartDates)
set thisStartDate to item i of theStartDates
if (not ((thisStartDate comes before dateRangeStart) or (thisStartDate comes after dateRangeEnd))) then
set end of eventDatesInRange to thisStartDate
set end of eventLocationsInRange to item i of theLocations
end if
end repeat
return {eventDatesInRange, eventLocationsInRange}
end filterToDateRange
-- Sort both the start-date and summary lists by start date.
on sortByDate(eventDatesInRange, eventLocationsInRange)
-- A sort-customisation object for sorting the summary list in parallel with the date list.
script custom
property summaries : eventLocationsInRange
on swap(i, j)
tell item i of my summaries
set item i of my summaries to item j of my summaries
set item j of my summaries to it
end tell
end swap
end script
CustomBubbleSort(eventDatesInRange, 1, -1, {slave:custom})
end sortByDate
-- CustomBubbleSort from "A Dose of Sorts" by Nigel Garvey.
-- The number of items to be sorted here is likely to be small.
on CustomBubbleSort(theList, l, r, customiser)
script o
property comparer : me
property slave : me
property lst : theList
on bsrt(l, r)
set l2 to l + 1
repeat with j from r to l2 by -1
set a to item l of o's lst
repeat with i from l2 to j
set b to item i of o's lst
if (comparer's isGreater(a, b)) then
set item (i - 1) of o's lst to b
set item i of o's lst to a
slave's swap(i - 1, i)
else
set a to b
end if
end repeat
end repeat
end bsrt
-- Default comparison and slave handlers for an ordinary sort.
on isGreater(a, b)
(a > b)
end isGreater
on swap(a, b)
end swap
end script
-- Process the input parameters.
set listLen to (count theList)
if (listLen > 1) then
-- Negative and/or transposed range indices.
if (l < 0) then set l to listLen + l + 1
if (r < 0) then set r to listLen + r + 1
if (l > r) then set {l, r} to {r, l}
-- Supplied or default customisation scripts.
if (customiser's class is record) then set {comparer:o's comparer, slave:o's slave} to (customiser & {comparer:o, slave:o})
-- Do the sort.
o's bsrt(l, r)
end if
return -- nothing
end CustomBubbleSort
-- Compose the text from the items in the start-date and summary lists.
on composeText(eventDatesInRange, eventLocationsInRange)
set txt to ""
set gap to linefeed & linefeed
repeat with i from 1 to (count eventDatesInRange)
set txt to txt & (date string of item i of eventDatesInRange) & (linefeed & item i of eventLocationsInRange & gap)
end repeat
return text 1 thru -3 of txt
end composeText
on main()
tell application "Calendar" to set {theStartDates, theLocations} to {start date, summary} of events of calendar "Golf"
set {dateRangeStart, dateRangeEnd} to getDateRange()
set {eventDatesInRange, eventLocationsInRange} to filterToDateRange(theStartDates, theLocations, dateRangeStart, dateRangeEnd)
sortByDate(eventDatesInRange, eventLocationsInRange)
set txt to composeText(eventDatesInRange, eventLocationsInRange)
tell application "TextEdit"
make new document with properties {text:txt}
activate
end tell
end main
main()
Here’s the output, but it’s missing location. I ran using AUG to OCT 2018
Wednesday, August 1, 2018
Golf
Friday, August 3, 2018
Golf
Wednesday, August 8, 2018
Golf
Thursday, August 9, 2018
Golf
Tuesday, August 14, 2018
Golf
Friday, August 17, 2018
Golf
Wednesday, August 22, 2018
Golf
Friday, August 24, 2018
Golf
Saturday, August 25, 2018
Golf
Tuesday, August 28, 2018
Golf
Friday, August 31, 2018
Golf
Friday, September 7, 2018
Golf
Saturday, September 8, 2018
Golf
Saturday, September 8, 2018
Golf
Friday, September 14, 2018
Golf
Friday, September 21, 2018
Golf
Thursday, September 27, 2018
Golf
Friday, September 28, 2018
Golf
Wednesday, October 3, 2018
Golf
Friday, October 5, 2018
Golf
Friday, October 12, 2018
Golf
How do I alter to add location to the output? I don’t understand where to put it or what field to use? And, where would one look to find this info? I tried using the dictionary, but when you don’t what what you are looking for it makes it a little difficult. Any help would be most appreciated.
This script is about 90% useful.