Spam Number Script Request – Extract Phone Number from FaceTime List

Can the following be scripted:

  • Copy selected phone number in iPhone’s recent call list.
  • Paste and search in Safari
  • Wait for user input
  • Option to switch to phone and block number or create new contact from number.

Do you want this to run on your Mac or iPhone?
If on the Mac, where would you get the iPhone's recent call list?

FWIW, KM does not run Mac Macros on any iOS device.

Thank you and sorry for not thinking it through before posting.

Facetime has the list. Here's what's current:

As you can see it's a lot of spam. I like to lookup the numbers in Safari before adding them to my blocked numbers list.

Just to answer the questions in case you have them, I do have three spam filters through Verizon, Hiya, and Call Protect.

I mostly don’t answer calls from unknowns but do have ads with my number so I get tempted to pick up and sometimes do pickup and every once in awhile it’s actually a lead, so this mess hampers my business. I’m assuming every spam call answered just primes the pump for lots more spam :roll_eyes:.

I also know the spam calls use fake numbers so building a large list of blocked numbers is a losing game and that's all I/we have at the moment.

It comes down to do I bother to build a list of fake phone numbers to block to possibly block a few calls or not bother at all, give up answering calls and simply enable “Silence Unknown Callers” on the iPhone and not allow anyone not in my address book to ring my phone.

I'm also guessing spammy calls will settle down after the election.

Hey @BernSh,

Yes, for the most part.

The appended macro will extract the static text from the list item in FaceTime that the mouse pointer is over.

NOTE – you need to place the cursor over the image of the contact on the left (or the placeholder of same).

Run the macro, and you'll get the static text(s) in a pop-up window.

This can be changed to a variable or to the clipboard and then you can add the Safari-Look-Up function yourself.


Extract Static Text from FaceTime List v1.00.kmmacros (6.2 KB)

It turns out to not be too difficult to scrape all of the static texts from the various rows of FaceTime.

  • Tested only on macOS 10.12.6 Sierra.


Scrape Static Text From Rows of FaceTime v1.00.kmmacros (6.6 KB)


It seems any contacts I’ve added an image to do not work. This isn’t important in my context of looking up potential spammy numbers as any contact I’ve added an image to are obviously not spam.

Asking curiously (and therefor uncommittedly), how does this work? Best guess is this section has the juiciest bits:

set objRef to {UIObject:obj, UIChildren:obj's UI elements}

set staticTextValueList to {}

tell application "System Events"

tell objRef to set objList to its UIChildren

repeat with i in objList
if class of i is static text then set end of staticTextValueList to value of i
end repeat

Trying to tease this apart by looking up class wasn’t bad as the AppleScript Language Guide shows up pretty quick and I have a vague idea about it. Trying to define objRef was more difficult as nothing specific comes up. Is there a resource to simply look up these terms to begin to decipher this? A Rosetta Stone for AS?

I did buy a bunch of books (AS 1-2-3, AS The definitive Guide, Learn AS The Comprehensive Guide…,Beginning AS, AS for Dummies, etc. and haven’t yet been able to push myself to get very far in any of them. Learning this stuff by reading just hasn’t been a very productive avenue for my learning style and the need hasn’t been great enough to push through the frustration to get clarity. I just go up a bit and fall back to the bottom. :person_climbing:t3:‍♂ :coffin: then repeat the process when an issue arises again. Likely a marsh I’ll not cross.



Ah so?

I'll look into that. It's likely that the clicked-on reference changes a bit.

System Events has a click command that returns a reference.

From there you have to tease out the relevant bits.

As for learning AppleScript – it takes real desire. You have to decide to endure the pain to get the prizes it offers.

The best way is to work on projects you're interested in – ask questions in the relevant places – and spend time with your books to get the vocabulary.

Currently the best AppleScript forum is Mark Alldritt's Late Night Software Forum.

You should also download and use Script Debugger Lite (free) or buy the full version of Script Debugger.

Script Debugger has tools to help you decipher AppleScript dictionaries that the stock Apple Script Editor does not.

That does not mean everything becomes easy due to Script Debugger. It's a professional developer tool that has a learning curve of its own – but anyone who writes AppleScript is a fool to not at least take advantage of the lite version.


1 Like

If you had Script Debugger you could turn on the debugger and step through scripts line-by-line to visualize what they do.


Yes, I'll see what I can do to move this Age of Suffering along. It seems we have the tools to do much better tho that vision has its price as well.

You are a good, kind, and generous man to offer guidance. :heart:

Maybe link your Learning AS back to Learning & Using AppleScript & JavaScript for Automation (JXA) if it adds to that resource.

Yes Script Debugger does shed some light.

You can delve deeply into all aspects of AppleScript with Script Debugger, but for working with System Events I recommend UI Browser to those who are willing to spend the money.

$55.00 is a pretty stiff price, but UI Browser has saved me so much time and aggravation it's been well worth it.

The paid version of Script Debugger is $99.99 – the Lite version is free.

(Some discounts are available.)


Hey @BernSh,

Well – it seems that Apple broke something in the accessibility structure, because System Events' click-event throws an error when clicking the picture. <shrug>

Appended is an update to the macro that should work if you click anywhere in the static-text or the blank space of the given row in FaceTime.

You can still click on empty picture placeholders.

You can't click on the CALL or INFO icons.


Extract Static Text from FaceTime List v2.00.kmmacros (8.1 KB)

Got UI Browser after seeing DanThomas' quick and dirty video TUTORIAL VIDEO: Using UI Browser and Keyboard Maeastro and even with my limited experience have been able to get a few things to work which was way cool.

Don't know if you're inclined to do video tutorials and it'd sure be helpful to see some walkthroughs with Script Debugger doing some basics like stepping through scripts with commentary on what to look for and how the various parts work. Just saying :upside_down_face:.

Line 40 "on error e number n"

threw this error when I went to complile this in Script Debugger:

Expected function name, command name or function name but found “error”.

Does the macro run?

This is on Big Sur?

It compiles fine for me in both SD5 and SD7 on Sierra and Mojave.


SD7 on 10.15.7 (maybe a Catalina issue?

Does not run. Macro looks like this when opened:

which I'm guessing is uncompiled so I copied it as this (which looks compiled here as I added the code block formatting before and after):

	# Screen dimensions
	set display to NSDeviceSize of deviceDescription() of item 1 ¬
		of NSScreen's screens() as record
	# Mouse position relative to bottom-left of screen
	set mouseLocation to NSEvent's mouseLocation as list of text or text
	# Adjust mouse position coordinates to be relative to top-left of screen
	set mouseLocation's y to (the display's height) - (mouseLocation's y)
	tell application "System Events"
		set clickObjectRef to click at the mouseLocation's {x, y}
		set objClass to class of clickObjectRef
		set objParent to missing value
		if objClass = row then
			set childObjectList to UI elements of clickObjectRef's UI element 1
		else if objClass ≠ UI element then
			repeat while objClass ≠ UI element
				set objParent to value of attribute "AXParent" of clickObjectRef
				set objClass to class of objParent
			end repeat
			set childObjectList to objParent's UI elements
			set childObjectList to clickObjectRef's UI elements
		end if
		set staticTextValueList to {}
		repeat with i in childObjectList
			if class of i is static text then set end of staticTextValueList to value of i
		end repeat
		set AppleScript's text item delimiters to linefeed
		return staticTextValueList as text
	end tell
on error e number n
	set e to e & return & return & "Num: " & n
	if n ≠ -128 then
			tell application (path to frontmost application as text) to set ddButton to button returned of ¬
				(display dialog e with title "ERROR!" buttons {"Copy Error Message", "Cancel", "OK"} ¬
					default button "OK" giving up after 30)
			if ddButton = "Copy Error Message" then set the clipboard to e
		end try
	end if
end try

and pasted into SD7 as new doc with these settings:

and got this:

The first macro did run – right?

The second macro is quite a bit more complex, so it could indeed be a Catalina issue.

See if this will compile by itself:

use framework "Foundation"
use scripting additions
property NSEvent : a reference to current application's NSEvent
property NSScreen : a reference to current application's NSScreen

   # Screen dimensions
   set display to NSDeviceSize of deviceDescription() of item 1 ¬
      of NSScreen's screens() as record
   # Mouse position relative to bottom-left of screen
   set mouseLocation to NSEvent's mouseLocation as any
   # Adjust mouse position coordinates to be relative to top-left of screen
   set mouseLocation's y to (the display's height) - (mouseLocation's y)


The first macro did run AND the first downloaded and imported into KM as compiled where the second didn't download and import as compiled.

Here's the full output for the entire 14 lines of latest test:

If you don't want calls or messages for your iPhone to appear on your iPad, iPod touch, or Mac, you can delete your phone number. To do this, you can use this method. Change the Apple ID password if the phone number you want to delete belongs to an iPhone that you cannot access. This removes all phone numbers from your iPad, iPod touch, and Mac devices. Calls and messages for deleted numbers will no longer appear on these devices. A simpler way, in my opinion, would be to use generate temp phone number, as it will take less time.

Thanks @SarahWorre.

How is the Apple ID password related to phone numbers stored on an Apple account, and when you say changing the password removes all the numbers, which logs of numbers are being removed?

Interesting idea to use temp numbers, haven't considered that.