Never thought of just adding math to the event…Simple and nice.
Thanks!!
Ok, I have used this script all summer, works great. Now my problem is that I have about 50 golf courses in my selection list…I want them to be sorted by name automatically, not by me updating each time I play a new course…here’s my ever growing list.
Any way to sort this list using code?
set theSummarylist to (choose from list {"Balmoral Woods ", "Big Run ", "Blackberry Oaks ", "Bliss Creek ", "Broken Arrow ", "Carillon ", "Carriage Greens ", "Cinder Ridge ", "Coyote Run ", "Devil’s Head The Glacier ", "Devil’s Head Prairie Glen ", "George W. Dunne ", "Dwight Country Club ", "Fox Bend ", "Glen Eagle ", "Glenwoodie ", "Green Garden ", "Heritage Bluffs ", "Hughes Creek ", "Inwood ", "Joliet Country Club ", "Kankakee Elks Club ", "Lawsonia Woodlands ", "Lawsonia Links ", "Lincoln Oaks ", "Mistwood ", "Myrtle Beach Indian Wells ", "Myrtle Beach Willbrook Plantation ", "Myrtle Beach National South Creek ", "Myrtle Beach Wild Wing Avocet ", "NaperBrook ", "Nettle Creek Country Club ", "Orchard Valley ", "Prairie Bluffs ", "Phillips Park ", "The Sanctuary ", "Silver Lakes ", "Settlers Hill ", "St.Andrews ", "Tamarack ", "Tana Farms ", "Thal Acres Links & Lanes ", "Tuckaway ", "Village Green ", "Wedgewood ", "Whitetail Ridge ", "Wolf Creek ", “Woodruff”
hI
try this,
borrowed the sorting routine from here:
https://macosxautomation.com/applescript/sbrt/sbrt-05.html
set the theSummarylist to {"Balmoral Woods ", "Big Run ", "Blackberry Oaks ", "Bliss Creek ", "Broken Arrow ", "Carillon ", "Carriage Greens ", "Cinder Ridge ", "Coyote Run ", "Devil's Head The Glacier ", "Devil's Head Prairie Glen ", "George W. Dunne ", "Dwight Country Club ", "Fox Bend ", "Glen Eagle ", "Glenwoodie ", "Green Garden ", "Heritage Bluffs ", "Hughes Creek ", "Inwood ", "Joliet Country Club ", "Kankakee Elks Club ", "Lawsonia Woodlands ", "Lawsonia Links ", "Lincoln Oaks ", "Mistwood ", "Myrtle Beach Indian Wells ", "Myrtle Beach Willbrook Plantation ", "Myrtle Beach National South Creek ", "Myrtle Beach Wild Wing Avocet ", "NaperBrook ", "Nettle Creek Country Club ", "Orchard Valley ", "Prairie Bluffs ", "Phillips Park ", "The Sanctuary ", "Silver Lakes ", "Settlers Hill ", "St.Andrews ", "Tamarack ", "Tana Farms ", "Thal Acres Links & Lanes ", "Tuckaway ", "Village Green ", "Wedgewood ", "Whitetail Ridge ", "Wolf Creek ", "Woodruff"}
simple_sort(the theSummarylist)
set the theSummarylist to choose from list the result
on simple_sort(my_list)
set the index_list to {}
set the sorted_list to {}
repeat (the number of items in my_list) times
set the low_item to ""
repeat with i from 1 to (number of items in my_list)
if i is not in the index_list then
set this_item to item i of my_list as text
if the low_item is "" then
set the low_item to this_item
set the low_item_index to i
else if this_item comes before the low_item then
set the low_item to this_item
set the low_item_index to i
end if
end if
end repeat
set the end of sorted_list to the low_item
set the end of the index_list to the low_item_index
end repeat
return the sorted_list
end simple_sort
set calendarName to "Golf"
set theSummarylist to (choose from list {"Balmoral Woods ", "Big Run ", "Blackberry Oaks ", "Bliss Creek ", "Broken Arrow ", "Carillon ", "Carriage Greens ", "Cinder Ridge ", "Coyote Run ", "Devil's Head The Glacier ", "Devil's Head Prairie Glen ", "George W. Dunne ", "Dwight Country Club ", "Fox Bend ", "Glen Eagle ", "Glenwoodie ", "Green Garden ", "Heritage Bluffs ", "Hughes Creek ", "Inwood ", "Joliet Country Club ", "Kankakee Elks Club ", "Lawsonia Woodlands ", "Lawsonia Links ", "Lincoln Oaks ", "Mistwood ", "Myrtle Beach Indian Wells ", "Myrtle Beach Willbrook Plantation ", "Myrtle Beach National South Creek ", "Myrtle Beach Wild Wing Avocet ", "NaperBrook ", "Nettle Creek Country Club ", "Orchard Valley ", "Prairie Bluffs ", "Phillips Park ", "The Sanctuary ", "Silver Lakes ", "Settlers Hill ", "St.Andrews ", "Tamarack ", "Tana Farms ", "Thal Acres Links & Lanes ", "Tuckaway ", "Village Green ", "Wedgewood ", "Whitetail Ridge ", "Wolf Creek ", "Woodruff
"})
if theSummarylist is false then display dialog "Select Golf Course From List" with icon stop buttons {"Exit"} default button {"Exit"}
simple_sort(the theSummarylist)
set the theSummarylist to choose from list the result
on simple_sort(my_list)
set the index_list to {}
set the sorted_list to {}
repeat (the number of items in my_list) times
set the low_item to ""
repeat with i from 1 to (number of items in my_list)
if i is not in the index_list then
set this_item to item i of my_list as text
if the low_item is "" then
set the low_item to this_item
set the low_item_index to i
else if this_item comes before the low_item then
set the low_item to this_item
set the low_item_index to i
end if
end if
end repeat
set the end of sorted_list to the low_item
set the end of the index_list to the low_item_index
end repeat
return the sorted_list
end simple_sort
set teetime to date ((display dialog "Enter date in this format MM DD, yyyy hh:mm:ss AM or PM" default answer "08 09 2018 11:00:00 AM" buttons {"Continue"} default button "Continue")'s text returned)
--set startdate to teetime --unused
--set endDate to startdate + 16200 --this requires conversion factors/dimensional analysis; see 'make event,' below
set alarm to -60
set theCost to (display dialog "Greens Fee:" default answer "$35.00" buttons {"Cancel", "Continue"} default button "Continue")'s text returned --wasn't originally in use
--> {button returned:"Continue", text returned:"$10.00"}
log "New Golf Date: " & "@ " & theSummarylist & " on " & teetime
tell application "Calendar"
tell (first calendar whose name is calendarName) --assumes it exists
make event at end with properties {summary:"Golf", start date:teetime, end date:teetime + 4.5 * hours, description:theCost, location:theSummarylist}
end tell
end tell
Thanks for your help. I added your code to my existing script and it looks like there’s an issue with the sort in the Settlers Hill and Silver Lakes - Silver Lakes should be sorted before Settlers Hill…Any help would be great.
Thanks
My bad, Settlers Hill should be before Silver Lakes… E before I.
I took a few of the names out of the original list order and put them at the end of the original list and ran the code again, it sorted them into the correct order.
"Silver Lakes ", "George W. Dunne "
set the theSummarylist to {"Balmoral Woods ", "Big Run ", "Blackberry Oaks ", "Bliss Creek ", "Broken Arrow ", "Carillon ", "Carriage Greens ", "Cinder Ridge ", "Coyote Run ", "Devil's Head The Glacier ", "Devil's Head Prairie Glen ", "Dwight Country Club ", "Fox Bend ", "Glen Eagle ", "Glenwoodie ", "Green Garden ", "Heritage Bluffs ", "Hughes Creek ", "Inwood ", "Joliet Country Club ", "Kankakee Elks Club ", "Lawsonia Woodlands ", "Lawsonia Links ", "Lincoln Oaks ", "Mistwood ", "Myrtle Beach Indian Wells ", "Myrtle Beach Willbrook Plantation ", "Myrtle Beach National South Creek ", "Myrtle Beach Wild Wing Avocet ", "NaperBrook ", "Nettle Creek Country Club ", "Orchard Valley ", "Prairie Bluffs ", "Phillips Park ", "The Sanctuary ", "Settlers Hill ", "St.Andrews ", "Tamarack ", "Tana Farms ", "Thal Acres Links & Lanes ", "Tuckaway ", "Village Green ", "Wedgewood ", "Whitetail Ridge ", "Wolf Creek ", "Woodruff", "Silver Lakes ", "George W. Dunne "}
Your main code is wrong.
set calendarName to "Golf"
set theSummarylist to (choose from list {"Balmoral Woods ", "Big Run ", "Blackberry Oaks ", "Bliss Creek ", "Broken Arrow ", "Carillon ", "Carriage Greens ", "Cinder Ridge ", "Coyote Run ", "Devil's Head The Glacier ", "Devil's Head Prairie Glen ", "George W. Dunne ", "Dwight Country Club ", "Fox Bend ", "Glen Eagle ", "Glenwoodie ", "Green Garden ", "Heritage Bluffs ", "Hughes Creek ", "Inwood ", "Joliet Country Club ", "Kankakee Elks Club ", "Lawsonia Woodlands ", "Lawsonia Links ", "Lincoln Oaks ", "Mistwood ", "Myrtle Beach Indian Wells ", "Myrtle Beach Willbrook Plantation ", "Myrtle Beach National South Creek ", "Myrtle Beach Wild Wing Avocet ", "NaperBrook ", "Nettle Creek Country Club ", "Orchard Valley ", "Prairie Bluffs ", "Phillips Park ", "The Sanctuary ", "Silver Lakes ", "Settlers Hill ", "St.Andrews ", "Tamarack ", "Tana Farms ", "Thal Acres Links & Lanes ", "Tuckaway ", "Village Green ", "Wedgewood ", "Whitetail Ridge ", "Wolf Creek ", "Woodruff
"})
# This instruction return {"Kankakee Elks Club "} or false
if theSummarylist is false then display dialog "Select Golf Course From List" with icon stop buttons {"Exit"} default button {"Exit"}
# So, when we are here, the handler sorts the single element list {"Kankakee Elks Club "}
simple_sort(the theSummarylist)
set the theSummarylist to choose from list the result
# Continue here
Try with :
set calendarName to "Golf"
set theOriginallist to {"Balmoral Woods ", "Big Run ", "Blackberry Oaks ", "Bliss Creek ", "Broken Arrow ", "Carillon ", "Carriage Greens ", "Cinder Ridge ", "Coyote Run ", "Devil's Head The Glacier ", "Devil's Head Prairie Glen ", "George W. Dunne ", "Dwight Country Club ", "Fox Bend ", "Glen Eagle ", "Glenwoodie ", "Green Garden ", "Heritage Bluffs ", "Hughes Creek ", "Inwood ", "Joliet Country Club ", "Kankakee Elks Club ", "Lawsonia Woodlands ", "Lawsonia Links ", "Lincoln Oaks ", "Mistwood ", "Myrtle Beach Indian Wells ", "Myrtle Beach Willbrook Plantation ", "Myrtle Beach National South Creek ", "Myrtle Beach Wild Wing Avocet ", "NaperBrook ", "Nettle Creek Country Club ", "Orchard Valley ", "Prairie Bluffs ", "Phillips Park ", "The Sanctuary ", "Silver Lakes ", "Settlers Hill ", "St.Andrews ", "Tamarack ", "Tana Farms ", "Thal Acres Links & Lanes ", "Tuckaway ", "Village Green ", "Wedgewood ", "Whitetail Ridge ", "Wolf Creek ", "Woodruff
"}
simple_sort(theOriginallist)
set theSummarylist to choose from list the result
if theSummarylist is false then display dialog "Select Golf Course From List" with icon stop buttons {"Exit"} default button {"Exit"}
# Continue here
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 9 octobre 2018 11:19:09
Got it working, thank to all.
So now I want to be able to peek into this calendar and return events with specific course I played. I’d like to get dates, cost and time from the data entered.
Here’s my example…
set calendarname to "Golf"
count "Carillon"
The above returns 15 items, but provides no details, just a raw number. Need a nudge in right direction…
something like this?
tell application "Calendar"
tell calendar "Golf"
show (first event where its summary = "Carillon")
end tell
end tell
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.
Tf you look at the dictionnary you would see:
event n : This class represents an event.
elements
contains attendees, display alarms, mail alarms, open file alarms, sound alarms; contained by calendars.
properties
description (text) : The events notes.
start date (date) : The event start date.
end date (date) : The event end date.
allday event (boolean) : True if the event is an all-day event
recurrence (text) : The iCalendar (RFC 2445) string describing the event recurrence, if defined
sequence (integer, r/o) : The event version.
stamp date (date) : The event modification date.
excluded dates (list of date) : The exception dates.
status (cancelled/confirmed/none/tentative) : The event status.
summary (text) : This is the event summary.
location (text) : This is the event location.
uid (text, r/o) : An unique todo key.
url (text) : The URL associated to the event.
At this time you are extracting the properties start date and summary.
To get what you want you must extract the property named location with :
tell application "Calendar" to set {theStartDates, theLocations} to {start date, location} of events of calendar "Golf"
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 11 octobre 2018 11:29:46
Thanks for the info…I was able to get it working. Now, I’d like to try and get the text output file records to be numbered sequentialy like this; 1), 2), 3) etc… Any guidance would be most welcomed.
-- 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, theDescriptions, theLocations} to {start date, description, location} 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()
If I understand well you may try :
on composeText(eventDatesInRange, eventLocationsInRange)
set txt to ""
set gap to linefeed & linefeed
repeat with i from 1 to (count eventDatesInRange)
set txt to txt & i & ") " & (date string of item i of eventDatesInRange) & (linefeed & item i of eventLocationsInRange & gap)
end repeat
return text 1 thru -3 of txt
end composeText
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 12 octobre 2018 16:28:43
Outstanding! Thanks for the help
I’d like to enhance this script but I don’t know how / where to do it. I want to add a few more rows of data to the notes section but I can’t find any examples of how to add rows to this field.
I’d like to be able to return to data from the theTargetPoints dialog and have it go to the description field, but I don’t know how to add another row to that field. Is it possible ?
There are about 5 more bits of data I’d like to add but if I can get and example of how to add one, I should be ok.
Another possibility is to “bastardize” another field that is not being used. Suggestions please…
set calendarName to "Golf"
set the theSummarylist to {"Balmoral Woods ", "Big Run "}
simple_sort(the theSummarylist)
set the theSummarylist to choose from list the result
on simple_sort(my_list)
set the index_list to {}
set the sorted_list to {}
repeat (the number of items in my_list) times
set the low_item to ""
repeat with i from 1 to (number of items in my_list)
if i is not in the index_list then
set this_item to item i of my_list as text
if the low_item is "" then
set the low_item to this_item
set the low_item_index to i
else if this_item comes before the low_item then
set the low_item to this_item
set the low_item_index to i
end if
end if
end repeat
set the end of sorted_list to the low_item
set the end of the index_list to the low_item_index
end repeat
return the sorted_list
end simple_sort
set teetime to date ((display dialog "Enter date in this format MM DD, yyyy hh:mm:ss AM or PM" default answer "03 30 2019 12:00:00 PM " with title "Set New Tee Time" buttons {"Cancel", "Continue"} default button "Continue")'s text returned)
set alarm to -60
set theCost to (display dialog "Greens Fee:" default answer "$35.00" with title "Enter Cost of Greens Fee" buttons {"Cancel", "Continue"} default button "Continue")'s text returned --wasn't originally in use
--> {button returned:"Continue", text returned:"$10.00"}
set theTargetPoints to (display dialog "Target Points:" default answer "14.00" with title "Enter Target Points" buttons {"Cancel", "Continue"} default button "Continue")'s text returned
log "New Golf Date: " & theSummarylist & " on " & teetime
tell application "Calendar"
tell (first calendar whose name is calendarName) --assumes it exists
make event at end with properties {summary:"Golf", start date:teetime, end date:teetime + 4.5 * hours, description:theCost, theTargetPoints:Target Points, location:theSummarylist}
--> how do I take the info entered in thetarget points and get it into the notes/description section? I have a few more rows of data I'd like to add like Actual Points, Cost of Game, Winnings, and Score. I know how to add the dialog, but can't figure out the rest...
end tell
end tell
Hi.
Concatenate theTargetPoints to theCost, with a linefeed or some other separator between them, and set the event’s description to the result.
set theNotes to theCost & linefeed & theTargetPoints
tell application "Calendar"
tell (first calendar whose name is calendarName) --assumes it exists
make event at end with properties {summary:"Golf", start date:teetime, end date:teetime + 4.5 * hours, description:theNotes, location:theSummarylist}
end tell
end tell
Your variable theSummaryList does indeed contain a list — the result of the choose from list command earlier on. It happens to be accepted in this form; but since the parameter required is text, not a list, and since it’s used to set the event’s location, not its summary, it would make sense to extract the text from the list before applying it to the event property and to use a more accurate label for the variable. Note too that it’s not considered good form put handlers in the middle of the main running code. They should all be at one end of it.
set calendarName to "@Test"
set theLocationList to {"Balmoral Woods ", "Big Run "}
set theLocationList to simple_sort(theLocationList)
set locationChoice to (choose from list theLocationList) -- Returns a list — or 'false' if the "Cancel" button's clicked.
if (locationChoice is false) then error number -128 -- Explicit "Cancel" error.
set theLocation to item 1 of locationChoice -- Otherwise get the single item of text from the list.
set teetime to date ((display dialog "Enter date in this format MM DD, yyyy hh:mm:ss AM or PM" default answer "03 30 2019 12:00:00 PM " with title "Set New Tee Time" buttons {"Cancel", "Continue"} default button "Continue")'s text returned)
set alarm to -60
set theCost to (display dialog "Greens Fee:" default answer "$35.00" with title "Enter Cost of Greens Fee" buttons {"Cancel", "Continue"} default button "Continue")'s text returned --wasn't originally in use
--> {button returned:"Continue", text returned:"$10.00"}
set theTargetPoints to (display dialog "Target Points:" default answer "14.00" with title "Enter Target Points" buttons {"Cancel", "Continue"} default button "Continue")'s text returned
log "New Golf Date: " & theLocation & " on " & teetime
set theNotes to theCost & linefeed & theTargetPoints
tell application "Calendar"
tell (first calendar whose name is calendarName) --assumes it exists
make event at end with properties {summary:"Golf", start date:teetime, end date:teetime + 4.5 * hours, description:theNotes, location:theLocation}
end tell
end tell
-- Handler(s).
on simple_sort(my_list)
set the index_list to {}
set the sorted_list to {}
repeat (the number of items in my_list) times
set the low_item to ""
repeat with i from 1 to (number of items in my_list)
if i is not in the index_list then
set this_item to item i of my_list as text
if the low_item is "" then
set the low_item to this_item
set the low_item_index to i
else if this_item comes before the low_item then
set the low_item to this_item
set the low_item_index to i
end if
end if
end repeat
set the end of sorted_list to the low_item
set the end of the index_list to the low_item_index
end repeat
return the sorted_list
end simple_sort
Thanks for your help…works excellently!
I can now collect all the data in one place and with the help of the Calendar Export app, I can export this data to Excel & manipulate as needed.
I took what I learned from the last script and attempted to make a simpler script tool to track my walking data. I used the same code and altered just a bit, but I keep getting this error…
“error “Calendar got an error: Can’t make date "Saturday, March 30, 2019 at 12:00:00 PM" into type text.” number -1700 from date “Saturday, March 30, 2019 at 12:00:00 PM” to text”
For the life of me I can’t see where my issue is…I have spent all morning trying to locate the culprit. What am I missing???
set calendarName to "Test"
set walkdata to date ((display dialog "Enter date in this format MM DD, yyyy hh:mm:ss AM or PM" default answer "03 30 2019 12:00:00 PM " with title "Set Walk Time" buttons {"Cancel", "Continue"} default button "Continue")'s text returned)
set TotalSteps to (display dialog "Total Steps:" default answer "10,000" with title "Enter Total Steps " buttons {"Cancel", "Continue"} default button "Continue")'s text returned
--set TotalDistance to (display dialog "Total Distance:" default answer "5.00" with title "Enter Total Miles Walked" buttons {"Cancel", "Continue"} default button "Continue")'s text returned
--set TotalTime to (display dialog "Total Time in Minutes:" default answer "60" with title "Enter Total Minutes " buttons {"Cancel", "Continue"} default button "Continue")'s text returned
--log "New Walk Info: " & TotalSteps & " on " & walkdata
set theNotes to walkdata
tell application "Calendar"
tell (first calendar whose name is calendarName) --assumes it exists
make event at end with properties {summary:"walk", start date:walkdata, end date:walkdata + 1.5 * hours, description:theNotes}
end tell
end tell
The event’s description value has to be text. You’re setting it to theNotes, which is set to walkdata, which is set to a date.