Mac AddressBook replacement?

Hi Jean-Yves. I am not at home and I didn’t test my application which use AddressBook with Xojo 2024r1. But I will and tell you the result.

1 Like

ok I’ve found the problem.
you have to name the plist file exactly “info.plist” and drop it into the project
or it does not get recognized by macos and you can’t authorize the app to access the addressbook.
it’s ok still working in xojo 2023r4.

Jean-Yves, someone (here on this forum) gave the script to add to Xojo to modify the info.Plist directly while building.
For the other persons who may read this thread, please note that the Script placed above the Build are executed before the Build 1, then Xojo build the application 2, then the script placed below the Build is executed 3.
My script in position 3 “ModifInfoPlist” is:

' A mettre APRES le Build pour s'exécuter après

If (CurrentBuildTarget = 7) or (CurrentBuildTarget = 16) Then ' Mac OS 32bit ou Mac OS 64bit
  Dim TpTextA, TpTextB, TpTxtErr as String ' https://www.mbsplugins.de/archive/2019-03-31/Required_keys_for_infoplist_fi
  
  ' OpenFile(CurrentBuildLocation) ' "c:\projects\IDEScriptTest.xojo_binary_project")
  ' OpenFile(CurrentBuildLocationNative)
  ' OpenFile("/Volumes/MBtom-HD2/Tampon/TextBatchConv.app/Contents/Resources/fr.lproj/Localizable.strings") ' Ouvre dans l'IDE
  
  ' Mac for Test : TpTextA = CurrentBuildLocationNative + "/" + CurrentBuildAppName + "/Contents/Resources/fr.lproj/Localizable.strings" ' NativePath
  
  TpTextA = CurrentBuildLocation + "/" + CurrentBuildAppName ' + ".app"
  
  ' Print(ProjectShellPath)
  
  TpTxtErr = ""
  TpTextB = DoShellCommand("/usr/bin/defaults write " + TpTextA + "/Contents/Info ""NSAppleEventsUsageDescription"" ""Modify folder window view, Add login item, Make alias, Select item.""")
  If not(TpTextB = "") Then
    If TpTxtErr = "" Then
      TpTxtErr = TpTextB
    Else
      TpTxtErr = TpTxtErr + EndOfLine + TpTextB
    End If
  End If
  TpTextB = DoShellCommand("/usr/bin/defaults write " + TpTextA + "/Contents/Info ""NSContactsUsageDescription"" ""Read Contacts in your AddressBook.""")
  If not(TpTextB = "") Then
    If TpTxtErr = "" Then
      TpTxtErr = TpTextB
    Else
      TpTxtErr = TpTxtErr + EndOfLine + TpTextB
    End If
  End If
  If not(TpTxtErr = "") Then Print(TpTxtErr)
End If

I added to my application an Applescript which add the application to the User account to be launched at startup, that’s why I add to the info.plist:
"/Contents/Info ““NSAppleEventsUsageDescription””
but for AddresseBook we need only:
"/Contents/Info ““NSContactsUsageDescription””

I just made a file name “info.plist” (this is important don’t use another name)
with the content of my post above
and drop it on the xojo project, and build.
it works and ask the user if the app can access to the address book
it even works in debug mode (but asks each time you compile)

The info.plist in my built application contains many other things. Does yours too? I suppose yes because I remember I read some times ago that a info.plist added in the project add its contents to the info.plist that Xojo generate.
The info.plist of my built ap is:

<?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>CFBundleDevelopmentRegion</key>
	<string>fr</string>
	<key>CFBundleExecutable</key>
	<string>MemoDate</string>
	<key>CFBundleIconFile</key>
	<string>App</string>
	<key>CFBundleIdentifier</key>
	<string>fr.Toroco.MemoDate</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>MemoDate</string>
	<key>CFBundlePackageType</key>
	<string>APPL</string>
	<key>CFBundleShortVersionString</key>
	<string>1.6.1</string>
	<key>CFBundleSignature</key>
	<string>????</string>
	<key>CFBundleSupportedPlatforms</key>
	<array>
		<string>MacOSX</string>
	</array>
	<key>CFBundleVersion</key>
	<string>1.6.1.3.0</string>
	<key>LSMinimumSystemVersion</key>
	<string>10.14</string>
	<key>NSAppleEventsUsageDescription</key>
	<string>Modify folder window view, Add login item, Make alias, Select item.</string>
	<key>NSContactsUsageDescription</key>
	<string>Read Contacts in your AddressBook.</string>
	<key>NSHighResolutionCapable</key>
	<true/>
	<key>NSHumanReadableCopyright</key>
	<string>©2007-2024, Toroco-Softwares</string>
</dict>
</plist>

the short info.plist I provide above, with only addressbook authorisations (and appleevents) is merged by the xojo compiler with all the necessary xml tags needed.
you only have to provide your non standard tags in it.