I want to build a CLI tool (using SwiftPM - without XCode) to read the contacts on my mac. The end goal is to use the notes field or maybe custom fields to build a simple CRM (customer relationship tool) to keep track of some things. It especially means reading the NOTE field, and also writing it back.
But... as mentioned on com.apple.developer.contacts.notes | Apple Developer Documentation reading the note field requires the com.apple.developer.contacts.notes.
How do I do that? If it runs locally only on my machine I am happy.
I wrote an entitlements.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.contacts.notes</key>
<true/>
</dict>
</plist>
And do
# build
swift build --configuration release --disable-sandbox --arch arm64
Building for production...
[2/2] Linking contacts
Build complete! (0.29s)
#sign
codesign --sign - --entitlements entitlements.plist --deep .build/release/contacts --force
.build/release/contacts: replacing existing signature
But upon running, I get:
./.build/release/contacts
fish: Job 1, './.build/release/contacts' terminated by signal SIGKILL (Forced quit)
Without signing I get:
*** Terminating app due to uncaught exception 'CNPropertyNotFetchedException', reason: 'A property was not requested when contact was fetched.'
*** First throw call stack:
(
0 CoreFoundation 0x000000018b1cc570 __exceptionPreprocess + 176
1 libobjc.A.dylib 0x000000018acbdeb4 objc_exception_throw + 60
2 CoreFoundation 0x000000018b1cc460 +[NSException exceptionWithName:reason:userInfo:] + 0
3 Contacts 0x000000019f8f9b74 -[CNContact note] + 152
4 contacts 0x0000000104879e04 $s8contacts3CliV3runyyKF + 436
5 contacts 0x000000010487a0c8 $s8contacts3CliV14ArgumentParser15ParsableCommandAadEP3runyyKFTW + 12
6 contacts 0x000000010487a160 contacts_main + 96
7 dyld 0x000000018acf90e0 start + 2360
)
libc++abi: terminating due to uncaught exception of type NSException
fish: Job 1, './.build/release/contacts' terminated by signal SIGABRT (Abort)
I am new to Swift and SwiftPM and the world of code signing.
I currently am NOT a member of the Apple Developer program but if needed I am (reluctantly) willing to pay 99$ to be able to sign/notarize/.. but since the goal is to only run it for myself I hppe there is a way to self-sign.
Do I need so sign my cli? Is it even possible to codesign command line tools (i've seen comments that it is not)? How would I do that? What am I missing?
Cheers,
Oliver