How can I search the list of blocked numbers for a specific number?

Someone is claiming they've called and I have no record of the call. How can I search my long list of blocked numbers for this number? Or, is there a way to organize the numbers starting with the area code?

MacBook Pro 13″, macOS 10.13

Posted on May 7, 2023 11:05 AM

Reply
Question marked as Top-ranking reply

Posted on May 7, 2023 12:38 PM

Yes you can - programmatically. Here is an AppleScript that gets the synchronized blocked phone numbers, allows you to enter a contiguous number string +n…n for the number, and then it will look that number up in a list of all blocked numbers. If there is a match or not, you will be informed with a dialog.


Copy and paste the following into Apple's Script Editor, click the hammer icon to compile, and then the ▶︎ button to run it.


Code:


# blocked_numbers.applescript

# Prompt user for a contiguous +n…n phone number to check against
# all blocked phone numbers. Report result in dialog.
# Tested: macOS 13.3.1 (a)
# VikingOSX, 2023-05-07, Apple Support Communities, No warranties expressed or implied.

use framework "Foundation"
use scripting additions

property ca : current application
property nil : a reference to missing value
property blockedKey : "values.__kCMFBlockListStoreTopLevelKey.value.__kCMFBlockListStoreArrayKey.__kCMFItemPhoneNumberUnformattedKey"
property blocked_plist : "~/Library/SyncedPreferences/com.apple.communicationsfilter.plist"

set locateNumber to text returned of (display dialog "Enter blocked number to look up as +numberstring" default answer "" with title "Check Number in Blocked List") as list

set mutArray to ca's NSMutableArray's array()
set matched to ca's NSArray's array()
set predBlocked to ca's NSPredicate's predicateWithFormat:"SELF IN[c] %@" argumentArray:locateNumber

set blockedPath to (ca's NSString's stringWithString:blocked_plist)'s stringByExpandingTildeInPath()
set theBlocked to ca's NSData's dataWithContentsOfFile:blockedPath
set {pdict, theError} to ca's NSPropertyListSerialization's propertyListWithData:theBlocked options:0 format:nil |error|:(reference)

if pdict is nil then
	error theError's localizedDescription() as text
	return
end if

mutArray's addObjectsFromArray:(pdict's valueForKeyPath:blockedKey)
if (count of mutArray) = 0 then
	return
end if

-- sort blocked numbers in numeric order
mutArray's sortUsingSelector:"caseInsensitiveCompare:"
set matched to mutArray's filteredArrayUsingPredicate:predBlocked

if (count of matched) > 0 then
	display dialog "Matched Number in Blocked list: " & matched as text with title "Blocked Phone Number Lookup"
else
	display dialog "Number is not among blocked numbers." with title "Blocked Phone Number Lookup"
end if
return


4 replies
Question marked as Top-ranking reply

May 7, 2023 12:38 PM in response to David Roy

Yes you can - programmatically. Here is an AppleScript that gets the synchronized blocked phone numbers, allows you to enter a contiguous number string +n…n for the number, and then it will look that number up in a list of all blocked numbers. If there is a match or not, you will be informed with a dialog.


Copy and paste the following into Apple's Script Editor, click the hammer icon to compile, and then the ▶︎ button to run it.


Code:


# blocked_numbers.applescript

# Prompt user for a contiguous +n…n phone number to check against
# all blocked phone numbers. Report result in dialog.
# Tested: macOS 13.3.1 (a)
# VikingOSX, 2023-05-07, Apple Support Communities, No warranties expressed or implied.

use framework "Foundation"
use scripting additions

property ca : current application
property nil : a reference to missing value
property blockedKey : "values.__kCMFBlockListStoreTopLevelKey.value.__kCMFBlockListStoreArrayKey.__kCMFItemPhoneNumberUnformattedKey"
property blocked_plist : "~/Library/SyncedPreferences/com.apple.communicationsfilter.plist"

set locateNumber to text returned of (display dialog "Enter blocked number to look up as +numberstring" default answer "" with title "Check Number in Blocked List") as list

set mutArray to ca's NSMutableArray's array()
set matched to ca's NSArray's array()
set predBlocked to ca's NSPredicate's predicateWithFormat:"SELF IN[c] %@" argumentArray:locateNumber

set blockedPath to (ca's NSString's stringWithString:blocked_plist)'s stringByExpandingTildeInPath()
set theBlocked to ca's NSData's dataWithContentsOfFile:blockedPath
set {pdict, theError} to ca's NSPropertyListSerialization's propertyListWithData:theBlocked options:0 format:nil |error|:(reference)

if pdict is nil then
	error theError's localizedDescription() as text
	return
end if

mutArray's addObjectsFromArray:(pdict's valueForKeyPath:blockedKey)
if (count of mutArray) = 0 then
	return
end if

-- sort blocked numbers in numeric order
mutArray's sortUsingSelector:"caseInsensitiveCompare:"
set matched to mutArray's filteredArrayUsingPredicate:predBlocked

if (count of matched) > 0 then
	display dialog "Matched Number in Blocked list: " & matched as text with title "Blocked Phone Number Lookup"
else
	display dialog "Number is not among blocked numbers." with title "Blocked Phone Number Lookup"
end if
return


This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How can I search the list of blocked numbers for a specific number?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.