Script error "My Card" after Ventura upgrade

I have used two scripts based on Eric’s/Christian’s original script with minor modifications;

– Smart template adding a localized project template to the current group

They both worked fine for years, until upgrading to Ventura.

Now one works fine, and the other gives this error;

An error occurred when accessing your Contacts card.
Please select your address card in Contacts and mark it as your card (via the menu command Card > Make This My Card). Then try again to use this template.

I have checked my contact card and it was marked as “My Card”. I tried marking a different card, then tried deleting my card and adding a new card etc., but still won’t work.

Any ideas what to try next?

Script 1 (works fine)

-- Smart template adding a localized project template to the current group
-- Written by Eric Böhnisch-Volkmann, modified by Christian Grunenberg
-- © 2009–2016 DEVONtechnologies, LLC


-- Default non-localized project name, also used to identify the resources
property pTemplateName : "%project%"
property pAboutDocument : "About this project"
property pBlackColor : {0, 0, 0} -- RTF text color


-- Import helper library
tell application "Finder" to set pathToAdditions to ((path to application id "DNtp" as string) & "Contents:Resources:Template Script Additions.scpt") as alias
set helperLibrary to load script pathToAdditions


try
	-- We're later working in DEVONthink, we need to cache localized strings while still in our realm
	set theProjectName to localized string pTemplateName
	
	tell application id "DNtp"
		-- Let the user change the project name
		set theProjectName to display name editor my helperLibrary's localizedString(pTemplateName) default answer "New Distributor" info (my helperLibrary's localizedString("Please enter a name for this Distributor")) as string
		
		set thePlaceholders to {|%project%|:theProjectName}
		
		
		-- Import the predefined structure
		set theTemplateFiles to helperLibrary's pathToLocalizedResources() & my helperLibrary's localizedString(pTemplateName)
		set theRecord to import theTemplateFiles placeholders thePlaceholders to current group
		set (name of theRecord) to (name of theRecord) -- Rename to user-defined project name
		
	end tell
	
on error errMsg number errNum
	if errNum ≠ -128 then display alert (localized string "An error occured when creating the new project structure") message errMsg as warning
end try

Script 2 (causes card error)

-- Smart template adding a localized project template to the current group
-- Written by Eric Böhnisch-Volkmann, modified by Christian Grunenberg
-- © 2009–2016 DEVONtechnologies, LLC


-- Default non-localized project name, also used to identify the resources
property pTemplateName : "%groupName%"
property pAboutDocument : "About this project"
property pBlackColor : {0, 0, 0} -- RTF text color


-- Import helper library
tell application "Finder" to set pathToAdditions to ((path to application id "DNtp" as string) & "Contents:Resources:Template Script Additions.scpt") as alias
set helperLibrary to load script pathToAdditions


try
	-- We're later working in DEVONthink, we need to cache localized strings while still in our realm
	set theProjectName to localized string pTemplateName
	
	tell application id "DNtp"
		-- Let the user change the project name
		set theProjectName to display name editor my helperLibrary's localizedString(pTemplateName) default answer "New Project" info (my helperLibrary's localizedString("Please enter a name for this project")) as string
		
		set thePlaceholders to {|%project%|:theProjectName}
		
		
		-- Import the predefined structure
		set theTemplateFiles to helperLibrary's pathToLocalizedResources() & my helperLibrary's localizedString(pTemplateName)
		set theRecord to import theTemplateFiles placeholders thePlaceholders to current group
		set (name of theRecord) to (name of theRecord & ": " & theProjectName as string) -- Rename to user-defined project name
		
	end tell
	
on error errMsg number errNum
	if errNum ≠ -128 then display alert (localized string "An error occured when creating the new project structure") message errMsg as warning
end try

Is DEVONthink allowed to script the Contacts application? Did you check that there’s one card marked as your card?

DEVONthink is allowed to access contacts, and has Full Disk Access.

Contacts definitely has my contact marked as “My Card”.

A screenshot of the error message would be useful.

Screenshot 2022-10-27 at 11.40.24

Does the second script work without this line? That’s the only difference I could spot.

set (name of theRecord) to (name of theRecord & ": " & theProjectName as string) -- Rename to user-defined project name

No, same error after deleting that line.

Is there anything else different, e.g. the template used for importing?

I don’t understand what that is?

Basically all I did was upgrade to Ventura. I don’t think I changed anything.

The scripts are not identical and there’s only one line different, meaning that one of them was customized (by you?). And the scripts are part of a template and therefore I wondered whether the templates were customized too, that’s all.

Remove the try block from the script and run it in Script Editor. Where is it erroring?

It highlights the word “error” in the last section.

Screenshot 2022-10-27 at 16.18.51

I understand now - yes, I deleted some folders and added an RTF file;

Just to add - I have an older MacBook 12" as a “duplicate” which I use for air travel.

It has identical DEVONthink settings, databases, contacts, calendar, email etc. It is always open and always synced up to date.

It runs OS X 12.6.1 and DEVONthink 3.8.6

The DEVONthink scripts work ok on that one.

I copied the script over, but same error.

It must be somehow related to the Contacts card on my Ventura system. Maybe there is a terminal instruction or an app which can “rebuild” a Mac contacts database?

That’s part of the try block.
You need to remove the try, and the on error through end try section.

Haha - you can tell I know very little about scripting…

I removed the Try and End try block including the error section. The script complied ok, but the once in DEVONthink the same Card error.

No worries!
Did you run the script from Script Editor after removing the try block?

Well, problem solved.

I edited the second script (which had worked fine) to be exactly the same as the first script (which triggered the “My Card” error).

Although the two scripts are identical, the second (edited) one now works fine. The first one still triggers the error.

It’s weird, because they are word for word identical - but anyway it’s now all good. :grinning:

That is very strange indeed but we’re glad it’s working now. :slight_smile: