1

How do I get apple script to include the current time in an imessage sent with apple script?

on run {input, parameters}

    tell application "Messages"
        set iMessageService to 1st service whose service type = iMessage
        set imessagebuddy to buddy "mymessagebuddy@domain.com" of iMessageService
        send "Message" to imessagebuddy
    end tell
end run
3
  • What have you tried that didn't work? How are you attempting to add the date/time currently? – Allan Feb 21 '18 at 12:52
  • Currently I have nothing at all to implement what I want. Just edited to show what I currently have that gets a message sent. But where "message" I want to have current date/time when the script runs. – Tim Apple Feb 21 '18 at 12:56
  • Please have a look at this – Tim Apple Feb 23 '18 at 4:43
1

Here is an example of how to add the time to the message:

set theTime to time string of (current date)

tell application "Messages"
    set iMessageService to 1st service whose service type = iMessage
    set imessagebuddy to buddy "mymessagebuddy@domain.com" of iMessageService
    send "Message " & theTime to imessagebuddy
end tell

In the OP you said "to include the current time" but in your comment you said "to have current date/time", so if you want the latter, then use the following example instead:

set theDateTime to (current date) as string

tell application "Messages"
    set iMessageService to 1st service whose service type = iMessage
    set imessagebuddy to buddy "mymessagebuddy@domain.com" of iMessageService
    send "Message " & theDateTime to imessagebuddy
end tell

By the way, if you plan on using AppleScript it would behove you to read the AppleScript Language Guide. You can get to it from: Script Editor > Help > Show AppleScript Language Guide

For reference to time string, it's shown under date under Class Reference in the AppleScript Language Guide.

For reference to current date, it's shown under Commands Reference in the AppleScript Language Guide.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .