Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dasx

macrumors 65816
Original poster
Jun 18, 2012
1,107
18
Barcelona
Hello there.
I'm trying to make a script that would launch when a process ends and send a message to my iPhone.

This is what I have so far:

Code:
#!/usr/bin/osascript
 
set me to "123456789"
#set me to "XXXXXX@gmail.com"
set appleid to "E:XXXXXX@gmail.com"

set today to current date
set currentDayNumber to day of today as string
set currentMonthName to month of today as string
set currentYear to year of today as string
set theDate to (currentMonthName & " " & currentDayNumber & ", " & currentYear & ".")
set theTime to time string of (current date)

set mssg to "Process finished at " & theTime & ", " & theDate

tell application "Messages"
    activate
    send mssg to buddy me of service appleid
end tell

Script works as it is, problem is when commenting first "set me" and uncommenting the second one, that I get:

execution error: Messages got an error: Can't send a message to yourself. (1)

Why doing it then, you'd ask. Well, thing is that if I send from my apple id to my cell phone number, in my phone appear two different conversations. One for the sent and another one for the received. And that's pretty annoying to be honest.

And if I open a new conversation with my apple id from my apple id directly from the app (which returns the error in the script) I have what I intend. One single conversation in my phone that show both the sent and received message.

Any ideas?

Thanks!
 
Hello there.
I'm trying to make a script that would launch when a process ends and send a message to my iPhone.

This is what I have so far:

Code:
#!/usr/bin/osascript
 
set me to "123456789"
#set me to "XXXXXX@gmail.com"
set appleid to "E:XXXXXX@gmail.com"

set today to current date
set currentDayNumber to day of today as string
set currentMonthName to month of today as string
set currentYear to year of today as string
set theDate to (currentMonthName & " " & currentDayNumber & ", " & currentYear & ".")
set theTime to time string of (current date)

set mssg to "Process finished at " & theTime & ", " & theDate

tell application "Messages"
    activate
    send mssg to buddy me of service appleid
end tell

Script works as it is, problem is when commenting first "set me" and uncommenting the second one, that I get:

execution error: Messages got an error: Can't send a message to yourself. (1)

Why doing it then, you'd ask. Well, thing is that if I send from my apple id to my cell phone number, in my phone appear two different conversations. One for the sent and another one for the received. And that's pretty annoying to be honest.

And if I open a new conversation with my apple id from my apple id directly from the app (which returns the error in the script) I have what I intend. One single conversation in my phone that show both the sent and received message.

Any ideas?

Thanks!

You need to change "me" to be something else, as "me" is a reserved keyword to send Apple Events to the current application. Change it to 'myEmail' or whatever, and it should work.
 
The word me already has a meaning in AppleScript:
AppleScript Fundamentals
Heading "The it and me Keywords"
AppleScript defines the keyword me to refer to the current script and the keyword it to refer to the current target.
Found by googling: applescript me


To fix, pick a different name for the variable. One that doesn't already have a meaning.
 
The word me already has a meaning in AppleScript:
AppleScript Fundamentals
Heading "The it and me Keywords"
AppleScript defines the keyword me to refer to the current script and the keyword it to refer to the current target.
Found by googling: applescript me


To fix, pick a different name for the variable. One that doesn't already have a meaning.

Well… actually that isn't a problem as 'me' never was the name of the variable. It's 'yo', its spanish translation. I just used 'me' when putting it here so it's all in english. (thanks anyways)

My workaround for now is:

Code:
tell application "System Events"
	activate application "Messages"
	delay 0.25
	keystroke "n" using {command down}
	delay 0.25
	keystroke "XXXXX@gmail.com" #my email
	delay 0.25
	keystroke return
	delay 0.25
	keystroke tab
	delay 0.25
	keystroke "Process finished."
	keystroke return
	delay 10
	keystroke "m" using {command down}
	activate application "Finder"
end tell

Which does exactly what I want and doesn't create two different conversations.

This workaround kind of sucks, so will only keep it as long as nobody comes with a solution for the original problem. :eek:
 
Well… actually that isn't a problem as 'me' never was the name of the variable. It's 'yo', its spanish translation. I just used 'me' when putting it here so it's all in english. (thanks anyways)

AppleScript may be aware of your primary language, and use 'yo' the same way it uses 'me'. Unless you actually changed the variable name to something that's definitely not a keyword, you haven't tried the suggestion.


If you want a solution for the original script, then post the original script, exactly as you have it. You can put in a placeholder for your email, but otherwise leave everything else exactly as is, in Spanish.

Then tell us exactly which OS version you're using, and please identify exactly which version of Spanish you have as your primary language. People here who don't know Spanish can test if they know exactly what you have. If they don't, they have to guess.

Accuracy is important in programming, and changing things that you think are insignificant may actually be significant.
 
AppleScript may be aware of your primary language, and use 'yo' the same way it uses 'me'. Unless you actually changed the variable name to something that's definitely not a keyword, you haven't tried the suggestion.


If you want a solution for the original script, then post the original script, exactly as you have it. You can put in a placeholder for your email, but otherwise leave everything else exactly as is, in Spanish.

Then tell us exactly which OS version you're using, and please identify exactly which version of Spanish you have as your primary language. People here who don't know Spanish can test if they know exactly what you have. If they don't, they have to guess.

Accuracy is important in programming, and changing things that you think are insignificant may actually be significant.

Ahh OK I see. Here's the code as is:

Code:
#!/usr/bin/osascript
 
set yo to "123456789"
#set yo to "XXXXXX@gmail.com"
set cuenta to "E:XXXXXX@gmail.com"

set today to current date
set currentDayNumber to day of today as string
set currentMonthName to month of today as string
set currentYear to year of today as string
set theDate to (currentMonthName & " " & currentDayNumber & ", " & currentYear & ".")
set theTime to time string of (current date)

set mensaje to "Process finished at " & theTime & ", " & theDate

tell application "Messages"
    activate
    send mensaje to buddy yo of service cuenta
end tell

Tried changing yo to something else but problem is the same:

execution error: Messages got an error: Can't send a message to yourself. (1)

Thanks!
 
Tried changing yo to something else but problem is the same:

execution error: Messages got an error: Can't send a message to yourself. (1)

Thanks!

Then I'd guess that Messages.app is specifically forbidding sending a message to whatever account is identified as "yourself".

If I were experimenting with this, I'd probably switch to the AppleScript Editor and see if there were more useful error messages. I would also probably run some trials with variables of different names, using fixed strings. Because it might be a subtle problem with the AppleScript, rather than something that Messages.app is inherently forbidding.

Maybe there's a way to change a setting or preference so a different account is temporarily "yourself", thus tricking Messages.app into sending the message.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.