Jump to content

Punctuation marks are somehow getting lost in this text messaging workflow

Recommended Posts

This is my first AppleScript workflow, I've spent almost two days trying to figure out what I'm doing wrong. Basically the alfred command is "text [name] [message] and it will send a message to the number associated with [name]. So far, I haven't incorporated Contacts into it, so the friend names are hard coded (friend1, friend2, etc changed in the code below for privacy). It works so far as basic functionality goes, but it's doing this really weird thing and I don't understand why. Basically, the punctuation marks (!@#%&*(),.?/"') are completely removed from the message, but ($ and ^) are fine for some reason. I tried escaping the characters with \, /, " ", and ' ', but none of those work. Can anyone point me in the right direction?


on alfred_script(q)

	--Save original applescript delimiter
	set saveTID to text item delimiters

	--Set new delimiter
	set text item delimiters to " "

	set buddyNumber to "+0"

	--Get name
	set buddyName to first word of q as text

	--Get message
	set buddyMessage to words 2 thru end in q as text

	log "name: " & buddyName
	log "message: " & buddyMessage

	if (buddyName) is "friend1" then
		set buddyNumber to "+18880009999"
	else if (buddyName) is "friend2" then
		set buddyNumber to "+19998880000"
	else if (buddyName) is "friend3" then
		set buddyNumber to "+10009998888"
	end if

	log "number: " & buddyNumber

	tell application "Messages"
		set targetBuddy to buddyNumber
		set targetService to id of first service whose service type = iMessage
		set textMessage to buddyMessage
		set theBuddy to buddy targetBuddy of service id targetService
		send textMessage to theBuddy
	end tell

	--Reset delimiter
	set text item delimiters to saveTID

end alfred_script


Edit: I'm an idiot for not reading the post instructions on the sticky. Here's the workflow, but you'll need to replace the fake numbers with ones that actually work (I use my own number for testing). Also, you need to have an active conversation in iMessages with the person you are trying to text, else it will simply open iMessage and do nothing. 


Alfred Version: 3.7

MacOS 10.14 Mojave

Text Message Workflow


Edited by RobRoyce
Added more info
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...