Friday, May 27, 2022

#1 2022-05-06 04:18:54 am

Funske
Member
From:: Netherlands
Registered: 2013-01-04
Posts: 6

Show events creation date

Hi,

If I copy an activity from the Calendar to the desktop and open it with text editor, I can see there the date the activity was created and the date it was last modified.
Is it possible to use an Applescript to show the creation date and modification date of the activity in question?
Or is there a way to show these dates in Calendar itself?
Thanks in advance for the effort to reply.

Model: iMac (24-inch, M1, 2021)
AppleScript: Scripteditor version 2.11 Applescript 2.8
Browser: Safari 605.1.15
Operating System: macOS 12


Have Fun

        Funske


Filed under: calendar, show, creation date

Offline

 

#2 2022-05-07 01:25:34 pm

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2285

Re: Show events creation date

Select the event in the Calendar.app, then run following script.
Or, make it service, using Automator.app.

Applescript:


use framework "Foundation"
use scripting additions

-- get Calendar.app's selection
set localUID to (iCal of ((current application's NSUserDefaults's alloc()'s initWithSuiteName:"com.apple.iCal")'s objectForKey:"SelectedEvents")) as text
set {selectedEventID, selectedCalendarID} to my sqlQuery(localUID)

-- find ICS file, read its content as text
set calendarsFolder to ("" & (path to library folder from user domain) & "Calendars") as alias
set calendarsFolderPath to quoted form of (POSIX path of calendarsFolder)
try
   set thePath to do shell script "find " & calendarsFolderPath & " -name " & selectedEventID & ".ics"
end try
set icsFileText to read thePath as «class utf8»

-- get Date Created and Date Modified
repeat with aParagraph in (paragraphs of icsFileText)
   if aParagraph begins with "CREATED:" then set DateCreated to text 9 thru -1 of aParagraph
   if aParagraph begins with "LAST-MODIFIED:" then set DateModified to text 15 thru -1 of aParagraph
end repeat
return {Date_Created:DateCreated, Date_Modified:DateModified}


-- parsing Calendar.app Cache to determine calendar ID by selected event localUID
on sqlQuery(localUID)
   local dateString, localUID
   if localUID contains "/" then
       set {TID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"}
       set {dateString, localUID} to text items of localUID
       set AppleScript's text item delimiters to TID
   end if
   set sqlText to "
SELECT DISTINCT zcalendaritem.zshareduid AS eventID
, znode.zuid as calID
FROM zcalendaritem
JOIN znode
ON znode.z_pk = zcalendaritem.zcalendar
AND zcalendaritem.zlocaluid = '"
& localUID & "'
;"

   set sqlPath to POSIX path of (path to library folder from user domain) & "Calendars/Calendar Cache"
   set {TID, text item delimiters} to {text item delimiters, "|"}
   set {eID, cID} to text items of (do shell script "echo " & quoted form of sqlText & " | sqlite3 " & quoted form of sqlPath)
   set text item delimiters to TID
   return {eID, cID}
end sqlQuery

Last edited by KniazidisR (2022-05-07 01:26:11 pm)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#3 2022-05-08 02:40:21 am

Funske
Member
From:: Netherlands
Registered: 2013-01-04
Posts: 6

Re: Show events creation date

Thanks KniazidisR for your reply!!
I just tried it, and in general it works fine. But with some I get this error message

set icsFileText to read thePath as «class utf8»


And the error is:

"/Users/fons/Library/Calendars//Agenda's 21-02-2022 12.50.icbu/Calendars/362D7AD7-49A0-49BB-876B-77625F04AD00.calendar/Events/DF0EF484-2C57-47E1-BFCE-50364B06BE8A.ics
/Users/fons/Library/Calendars//19BE46A1-779D-4E29-9D41-335E7D758FCB.caldav/38572741-62FA-4655-9AAD-BC6649AF4E4C.calendar/Events/DF0EF484-2C57-47E1-BFCE-50364B06BE8A.ics" cannot be converted into type of file.


I know what causes this. I sometimes have activities that should really be in Reminders, but they are in Calendar because it is easier for me to change them quickly.

When I look at these activities in Text Editor, they have a number of lines that start with
"EXDATE"
Example:

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Apple Inc.//macOS 12.3.1//EN
CALSCALE:GREGORIAN
BEGIN:VTIMEZONE
TZID:Europe/Berlin
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
DTSTART:19810329T020000
TZNAME:CEST
TZOFFSETTO:+0200
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
DTSTART:19961027T030000
TZNAME:CET
TZOFFSETTO:+0100
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
TRANSP:OPAQUE
DTEND;TZID=Europe/Berlin:20211015T180500
X-APPLE-TRAVEL-ADVISORY-BEHAVIOR:AUTOMATIC
UID:DF0EF484-2C57-47E1-BFCE-50364B06BE8A
EXDATE;TZID=Europe/Berlin:20211015T180000
EXDATE;TZID=Europe/Berlin:20220401T180000
EXDATE;TZID=Europe/Berlin:20220429T180000
EXDATE;TZID=Europe/Berlin:20220318T180000
EXDATE;TZID=Europe/Berlin:20220415T180000
EXDATE;TZID=Europe/Berlin:20211029T180000
EXDATE;TZID=Europe/Berlin:20220121T180000
EXDATE;TZID=Europe/Berlin:20211210T180000
EXDATE;TZID=Europe/Berlin:20220204T180000
EXDATE;TZID=Europe/Berlin:20220304T180000
EXDATE;TZID=Europe/Berlin:20211112T180000
EXDATE;TZID=Europe/Berlin:20211224T180000
EXDATE;TZID=Europe/Berlin:20211126T180000
EXDATE;TZID=Europe/Berlin:20220107T180000
EXDATE;TZID=Europe/Berlin:20220218T180000
DTSTAMP:20220429T213458Z
SEQUENCE:0
SUMMARY:Groenbak binnen zetten
LAST-MODIFIED:20220429T213454Z
DTSTART;TZID=Europe/Berlin:20211015T180000
CREATED:20190530T170742Z
RRULE:FREQ=WEEKLY;INTERVAL=2
BEGIN:VALARM
X-WR-ALARMUID:9F3F66D8-5504-442B-A031-2918D3383B11
UID:9F3F66D8-5504-442B-A031-2918D3383B11
TRIGGER:PT0S
X-APPLE-DEFAULT-ALARM:TRUE
ATTACH;VALUE=URI:Chord
ACTION:AUDIO
END:VALARM
END:VEVENT
END:VCALENDAR

Last edited by Funske (2022-05-08 02:59:00 am)


Have Fun

        Funske

Offline

 

#4 2022-05-08 02:58:23 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2285

Re: Show events creation date

Funske wrote:

I just tried it, and in general it works fine. But with some I get this error message

set icsFileText to read thePath as «class utf8»


And the error is:

"/Users/fons/Library/Calendars//Agenda's 21-02-2022 12.50.icbu/Calendars/362D7AD7-49A0-49BB-876B-77625F04AD00.calendar/Events/DF0EF484-2C57-47E1-BFCE-50364B06BE8A.ics
/Users/fons/Library/Calendars//19BE46A1-779D-4E29-9D41-335E7D758FCB.caldav/38572741-62FA-4655-9AAD-BC6649AF4E4C.calendar/Events/DF0EF484-2C57-47E1-BFCE-50364B06BE8A.ics" cannot be converted into type of file.


It seems, you selected this time some event shared by different calendars. Updated script, which takes this into account:

Applescript:


use framework "Foundation"
use scripting additions

-- get Calendar.app's selection
set localUID to (iCal of ((current application's NSUserDefaults's alloc()'s initWithSuiteName:"com.apple.iCal")'s objectForKey:"SelectedEvents")) as text
set {selectedEventID, selectedCalendarID} to my sqlQuery(localUID)

-- find ICS file, read its content as text
set calendarsFolder to ("" & (path to library folder from user domain) & "Calendars") as alias
set calendarsFolderPath to quoted form of (POSIX path of calendarsFolder)
set selectedCalendarPath to do shell script "find " & calendarsFolderPath & " -name " & selectedCalendarID & ".calendar"
set thePath to do shell script "find " & selectedCalendarPath & " -name " & selectedEventID & ".ics"
set icsFileText to read thePath as «class utf8»

-- get Date Created and Date Modified
repeat with aParagraph in (paragraphs of icsFileText)
   if aParagraph begins with "CREATED:" then set DateCreated to text 9 thru -1 of aParagraph
   if aParagraph begins with "LAST-MODIFIED:" then set DateModified to text 15 thru -1 of aParagraph
end repeat
return {Date_Created:DateCreated, Date_Modified:DateModified}


-- parsing Calendar.app Cache to determine calendar ID by selected event localUID
on sqlQuery(localUID)
   local dateString, localUID
   if localUID contains "/" then
       set {TID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"}
       set {dateString, localUID} to text items of localUID
       set AppleScript's text item delimiters to TID
   end if
   set sqlText to "
SELECT DISTINCT zcalendaritem.zshareduid AS eventID
, znode.zuid as calID
FROM zcalendaritem
JOIN znode
ON znode.z_pk = zcalendaritem.zcalendar
AND zcalendaritem.zlocaluid = '"
& localUID & "'
;"

   set sqlPath to POSIX path of (path to library folder from user domain) & "Calendars/Calendar Cache"
   set {TID, text item delimiters} to {text item delimiters, "|"}
   set {eID, cID} to text items of (do shell script "echo " & quoted form of sqlText & " | sqlite3 " & quoted form of sqlPath)
   set text item delimiters to TID
   return {eID, cID}
end sqlQuery

Last edited by KniazidisR (2022-05-08 03:01:26 am)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#5 2022-05-08 03:05:43 am

Funske
Member
From:: Netherlands
Registered: 2013-01-04
Posts: 6

Re: Show events creation date

Wow KniazidisR, great!!

Now the only thing that I have to do is split the days into DD-MM-YYYY and then I am very happy!!


Have Fun

        Funske

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)