Script No Longer Works Under El Captain, Please Help...

I wrote the following script to delete messages within iMessage…


-- AppleScript to delete Message's Chats

tell application "Messages"
	
	-- Determine the Message's window state at script start up so it can be returned said state at end of sccript
	-- NOTE: It was determined through testing that Message has only one visible window
	-- NOTE: It was determined through testing that Message's window's index property only applies to the Message's window as opposed to all windows
	if (exists (windows whose visible = true)) then
		set AppWindowStatus to "Visible"
	else if (exists (windows whose minimized = true)) then
		set AppWindowStatus to "Minimized"
	else
		set AppWindowStatus to "Closed"
	end if
	-- display dialog "Message's window status is" & " " & "\"" & AppWindowStatus & "\"" buttons {"OK"} default button 1-- NOTE:  Comment out / delete once final.  Used to test AppWindowStatus
	
	-- Initialize the list chatCountList which is used to communicate the message number to the user
	-- Initialize the counter/variable deletedChats which counts the number of Chats which are deleted
	-- Initialize the list myChats which contains information on all Chats 
	-- Initialize the list myChatsOrdered which contains the list of dispalyed information sorted by update time
	set chatCountList to {"1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th", "10th", "11th", "12th", "13th", "14th", "15th", "16th", "17th", "18th", "19th", "20th", "21st", "22nd", "23rd", "24th", "25th", "26th", "27th", "28th", "29th", "30th", "31st", "32nd", "33rd", "34th", "35th", "36th", "37th", "38th", "39th", "40th", "41st", "42nd", "43rd", "44th", "45th", "46th", "47th", "48th", "49th", "50th"}
	set deletedChats to 0
	set myChats to chats
	set myChatsOrdered to {}
	
	
	-- Determine / extract the information to be displayed
	repeat with aChat in myChats
		
		set aChatParticipant to participants of aChat -- Get the Chat's participant's name
		set aChatParticipantName to first name of item 1 of aChatParticipant & " " & last name of item 1 of aChatParticipant
		
		set aChatService to id of aChat -- Get the Chat's telepehone number and type [i.e. iMessage or SMS] 
		if (character 1 of aChatService is "i") then
			set aChatTelephone to (text 12 through -1 of aChatService)
			set aChatType to "iMessage"
		else if (character 1 of aChatService is not "i") then
			set aChatTelephone to (text 7 through -1 of aChatService)
			set aChatType to "SMS"
		end if
		
		set aChatTime to updated of aChat -- Get the Chat's updated time
		-- log (current date) -- NOTE:  Comment out / delete once final.  Used to test "current date"
		-- log aChatTime  -- NOTE: Comment out / delete once final.  Used to test aChatTime
		set aChatTime to (current date) - aChatTime
		
		set end of myChatsOrdered to {aChatTime, aChatParticipantName, aChatTelephone, aChatType, aChat} -- Set list of data items to be sorted
		-- log "myChatsOrdered Before Sort" -- NOTE:  Comment out / delete once final.  Used to test myChatsOrdered before sort
		-- log myChatsOrdered -- NOTE:  Comment out / delete once final.  Used to test myChatsOrdered before sort
	end repeat
	
	-- Sort myChatsOrdered based on aChatTime [i.e. newest to oldest]
	-- Set callSort to load a compiled sorting script
	set sortFunction to load script "Macintosh HD:Users:JoelC:Documents:Apple:Scripts:Utilities:20141125_script to sort a list of items_specific.scpt" as alias
	set myChatsOrdered to simple_sort(myChatsOrdered) of sortFunction
	
	-- log "myChatsOrdered After Sort" -- NOTE:  Comment out / delete once final.  Used to test myChatsOrdered after sort
	-- log myChatsOrdered -- NOTE:  Comment out / delete once final.  Used to test myChatsOrdered after sort
	
	-- Determine which Chats [i.e. all Chats or specifc Chats] to delete and then delete them				
	if ((count of myChats) > 0) then
		
		display dialog "Do you want to delete all chats or specific chats?" buttons {"All chats", "Specifc chats"} default button 2 with icon note
		set chatDeletePreference to button returned of result
		set chatDeleteSelected to 0
		
		if ((chatDeletePreference = "All chats") is true) then
			repeat with deletedChats from 1 to (count myChatsOrdered) -- Branch when user has elected to delete all Chats
				set chatToDeleteData to item deletedChats of myChatsOrdered
				set aChat to item 5 of chatToDeleteData
				delete aChat
			end repeat
			display dialog "As elected, all " & deletedChats & " chats have been deleted..." buttons {"OK"} default button 1 with icon note
			
		else
			
			repeat with deletedChats from 1 to (count myChatsOrdered) -- Branch when user has elected to delete specific Chats
				set deletedChatsString to item deletedChats of chatCountList
				display dialog "Do you want to delete the" & " " & deletedChatsString & " " & "chat which is an " & item 4 of item deletedChats of myChatsOrdered & " from " & item 2 of item deletedChats of myChatsOrdered & " " & " which has an e-mail address or telephone number of " & item 3 of item deletedChats of myChatsOrdered & "?" buttons {"Yes", "No"} default button 2 with icon note
				
				set chatDeleteSpecific to button returned of result
				
				if ((chatDeleteSpecific = "Yes") is true) then
					set chatDeleteSelected to chatDeleteSelected + 1
					set chatToDeleteData to item deletedChats of myChatsOrdered
					set aChat to item 5 of chatToDeleteData
					delete aChat
				end if
			end repeat
			display dialog "As elected, " & chatDeleteSelected & " specifc chats out of " & deletedChats & " total chats have been deleted..." buttons {"OK"} default button 1 with icon note
			
		end if
		
	else
		display dialog "No chats to delete..." buttons {"OK"} default button 1 with icon note
	end if
	
	
	-- Return the Messages window state to the same state at script start up state	
	if (AppWindowStatus = "Visible") then
		reopen windows
	else if (AppWindowStatus = "Minimized") then
		try
			keystroke "cmd-m"
		end try
	else
		quit
	end if
	
end tell


The script worked perfectly under Yosemite (i.e. the only thing that I am aware of that changed is the upgrade from Yosemite to El Capitain)…the script is failing at the line that reads:



set aChatParticipant to participants of aChat -- Get the Chat's participant's name


with the error message "Can’t get participants of text chat id "iMessage;-;+14163005811"." number -1728 from participants of text chat id “iMessage;-;+14163005811”.

Please explain the problem and provide a fix.

TIA,

Joel

It looks like scripting of chats is broken – no properties are working here.

bugreport.apple.com

Shane, appreciate the fast response, good to know that I did not miss something…I will submit a bug report.

Thanks again,

Joel

Hmmmm, cannot report the bug because I am not an Apple Developer (i.e. the website will not allow me to login)…this is a little disappointing!

You can report a bug with a free Apple Developer account.

Right. And in case it’s not obvious, that just involves going to:

developer.apple.com/register/

and entering the Apple ID you want to use.

DJ Bazzie and Shane, appreciate the advice and the link but it appears to be a no go as there does not – at least based on my attempt – to be a way to get a FREE developer account. Although I have already e-mailed Apple on this I wont here back from them until next week. I will provide an update once I have a response from Apple.

Perhaps someone here who has a account can report the bug?

Thanks again,

Joel

Did you enter your Apple ID (assuming you have one) at that page?

Yes, I entered my Apple ID, I then went through the registration process but there is no option to get free account, the only option is for a paid account, at least as it took me through the process…I went back in a second time, it confirmed that I had agreed to the NDA, I had provided my personal information, BUT still had to pay to complete the process.

I considered paying but concluded it did not make sense as i) I develop just for myself and even that is limited as you have probably noted based on my postings here and ii) I do not have the time to play with the beta versions of the OS X, etc.

I guess I need to wait until Apple gets back to me next week.

Thx,

Joel

For those interested and following, I am still waiting for a response from Apple (i.e. their one response is not a reality), will update further once I hear back…thx…

For those interested and following, I did finally hear back from Apple and note that it is possible to create a register a developer account for weekend warriors like me who do not have time / need / want the software that goes with being a paying Apple developer BUT to do so you need to call Apple…so, I called, I got in and bug registered.

Thanks for the help…

Good news on both counts.

I am confused!

I reported the above noted bug to Apple who responded that the script is working for them. I find this very confusing as i) the script is definitely not working for me and ii)Shane was kind enough to take a look at it an advised that the scripting of chats looks broken to him.

I would like to get this fixed / working but seem to be “stuck”. Would appreciate any options or suggestions as to next steps from this who do much more developing than me.

Thanks,

Joel

As I have no, use for it, I don’t use Messages.
Maybe the answer given by the engineers means that the problem no longer strikes in El Capitan 10.11.2. As you see, I am optimistic.

Yvan KOENIG running El Capitan 10.11.1 in French (VALLAURIS, France) samedi 28 novembre 2015 16:21:00

Yvan, once can only hope that it could / would be that simple BUT I would both expect and hope that the engineer reviewing the bug would have tested it based on 10.11.1 which is the OS I referenced when reporting the bug.

Thanks,

Joel

Well, unfortunately the release of 10.11.2 did not solve the problem! I guess that I continue to wait…

Apologies for revisiting this problem / thread but i) the problem continues to exist under OS 10.12 and ii) there is no response from Apple when I submit a bug report.

I would appreciate you guys taking another look at the Original Posting and let me know whether anyone has any new ideas or thoughts about how to get this script working again.

With much thanks!

I am still trying to solve this problem so will add some additional information in the hope that someone can assist me in solving this!

First I decided to run the script with Replies enabled and got the following output:

tell application “Messages”
exists every window whose visible = true
→ true
get every chat
→ {text chat id “iMessage;-;+16478360641”, text chat id “SMS;-;+14164509808”}
get participants of text chat id “iMessage;-;+16478360641”
→ error number -1728 from participants of text chat id “iMessage;-;+16478360641”

Result:
error “Messages got an error: Can’t get participants of text chat id "iMessage;-;+16478360641".” number -1728 from participants of text chat id “iMessage;-;+16478360641”

Second I looked up what error 1728 means and learnt that it means

from https://developer.apple.com/library/content/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_error_codes.html#//apple_ref/doc/uid/TP40000983-CH220-SW5

With the added insight hopefully someone will help me with the fix.

Thanks in advance.