Can AppleScript display when a script was last run? Is there a way for an AppleScript command to display the last time it was run? I have a few scripts where it would be useful to have a timestamp of the last time it was run for logging purposes. I am very green to scripting, any ideas are welcome.
You can retrieve the time that any file was last accessed using the command-line tool stat with the following arguments:

    stat -f "%Sa" -t '%Y-%m-%d %H:%M:%S' /path/to/file



-f "%Sa": This requests only the file access data, as stat can provide other data as well, such as modification times, creation times, device information, ownership and permission data, etc.  See man stat if you want to know more about the other capabilities of stat.
-t "%Y-%m-%d %H:%M:%S": This tells stat what format to output the date and time in.  You can change this to suit your needs, but for the purposes of this answer, I chose a standardised format that output this for one of my AppleScripts: 2018-03-31 16:55:42.


Bear in mind that the access time for an AppleScript file will be updated, not just if it is run, but also if it gets read or copied or moved.

To use this within an AppleScript, you can wrap it within a do shell script:

    do shell script "stat -f '%Sa' -t '%Y-%m-%d %H:%M:%S' " &amp; ¬
        quoted form of POSIX path of theFileAlias