In AppleScript if you have a string with a date and try to convert it to a class of date it will error out in Finder and System Events. Example:
set testDate to "Friday, September 21, 2018 at 6:54:29 PM" set testResult to date testDate return testResult renders:
When placing the above code in a System Event:
tell application "System Events" set testDate to "Friday, September 21, 2018 at 6:54:29 PM" set testResut to date testDate return testResut end tell returns:
System Events got an error: Can’t get date "Friday, September 21, 2018 at 6:54:29 PM".
Trying to place the above in a Finder tell:
tell application "Finder" set testDate to "Friday, September 21, 2018 at 6:54:29 PM" set testResut to date testDate return testResut end tell Finder got an error: Can’t get date "Friday, September 21, 2018 at 6:54:29 PM".
What should I use to be able to convert a date string to an actual date if I'm already using either System Events or Finder? The only alternative I've found is to create a handler:
tell application "System Events" set testDate to "Friday, September 21, 2018 at 6:54:29 PM" return my stringDate(testDate) end tell on stringDate(theString) set attempt to date theString return attempt end stringDate How can I do a date conversion in a System Event or Finder tell block?
There's been discussion in comments with the supplied answer but given the system specs of:
macOS High Sierra version 10.13.6
and copied solution:
tell application "System Events" set testDate to "Friday, 21 September, 2018 at 6:54:29 PM" set testResult to my (date testDate) end tell Opened a new Script Editor:
Pasted code solution:
Compiled code solution:
Ran code solution:
Issue still persists.




