Jump to content
RobRoyce

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

Share this post


Link to post

I guess I solved my own problem, turns out AppleScript doesn't include punctuation marks in the "word" category. I changed all instances of "word" to "text item" and it worked perfectly!

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...