Reputation: 1106
I'm trying to create a script to log my current time and my finish time do a specific action them sent an email with this same time variable and create a calendar event with this time variable :
set FinsihDate to (current date) + 10 * hours + 30 * minutes
set startingDate to (current date)
set plistR to {FinsihDate:FinsihDate, starteddate:current date}
tell application "System Events"
set plistf to make new property list file ¬
with properties {name:"~/Desktop/MY_Time.plist"}
set plistf's value to plistR
end tell
## Email
property lastWindowID : missing value
tell application "Mail"
set windowIDs to id of windows
if windowIDs does not contain lastWindowID then
set newMessage to make new outgoing message with properties {subject:"Started early", content:"Hi ..., \n \nI started early today : " & (current date) & ", I will leave at " & FinsihDate & "\n \nKind Regards,\nKevin " & return & return}
tell newMessage
set visible to true
make new to recipient at end of to recipients with properties {name:"Name", address:"@apple.com"}
end tell
activate
set lastWindowID to id of window 1
else
tell window id lastWindowID
set visible to false
set visible to true
end tell
activate
end if
end tell
set startDate to date (current date)
set endDate to date FinsihDate
tell application "Calendar"
tell (first calendar whose name is "calendar")
make new event at end of events with properties {summary:"Work", start date:startDate, end date:endDate, description:"ITS Fraud Prevention", location:"Apple"}
end tell
end tell
Time format
the time format on the email is " Monday 4 June 2018 at 14:25:57," when I just want 14:25
I tried this :
set myTime to (time string of (current date)) + 10 * hours + 30 * minutes
Result: error "Can’t make \"14:27:02\" into type number." number -1700 from "14:27:02" to number
When creating the Calendar event I have this error
error "Can’t get date (date \"Monday 4 June 2018 at 14:29:34\")." number -1728 from date (date "Monday 4 June 2018 at 14:29:34")
Upvotes: 1
Views: 796
Reputation: 6102
Thanks for itemising the individual errors that you encountered and want fixing. This made is so much easier for me to read this question and decide it was one I wanted to answer, because I don't actually have to test your script at all as I can immediately see what the problems are:
① Your parentheses are in the wrong place. Change this:
set myTime to (time string of (current date)) + 10 * hours + 30 * minutes
to this:
set myTime to time string of ((current date) + 10 * hours + 30 * minutes)
② The error indicates that you've tried to take a variable of type date
and then declare it again as type date
. AppleScript doesn't like this.
Change these two lines:
set startDate to date (current date)
set endDate to date FinsihDate
to this:
set startDate to (current date)
set endDate to FinsihDate
I haven't tested the rest of the script.
P.S. You misspelled your variable name FinsihDate
(which I assume is meant to be FinishDate
). However, it's misspelled consistently throughout the script, so it doesn't make any practical difference.
Upvotes: 1