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.
Select the event in the Calendar.app, then run following script.
Or, make it service, using Automator.app.
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
Thanks KniazidisR for your reply!!
I just tried it, and in general it works fine. But with some I get this error message
And the error is:
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:
It seems, you selected this time some event shared by different calendars. Updated script, which takes this into account:
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