AppleEvent Handler Failed

Hi all,

I’ve another annoying AppleScript question/problem.

I’ve written a script which iterates groups and extracts file metadata into a DT sheet. It’s iterating and extracting the data just fine, but when it goes to save the data to the sheet’s cells, it throws the error “AppleEvent handler failed”. Whats odder is that, when I step thought the script, the data is in fact written to the sheet so I don’t know what its complaining about.

So far I’ve tried, disabling SIP on my Mac (as I recently had to do a fresh install) and repaired disk permissions. If I wrap the offending line in a try brace it works perfectly, so I’ve no idea why this line both appears to work, and throw an error.

These lines are fine, they just explain how the further vars are set (letters are just for legibility):

set doc_tsv to create record with {type:sheet, columns:{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o"}, name:"files"} in a_group
set doc_tsv_cells to cells of doc_tsv

And after I iterate my files, add the metadata to the doc_tsv_cells as a nested dict:

copy {a, b, c, d, e, f, g, h, i, j, k, l, m, n, o} to end of doc_tsv_cells

And finally after iterating al my files, I try to save the data to the sheet using:

set cells of doc_tsv to doc_tsv_cells

And that is where it fails. But it works, as data is written back, but it throws a fatal error, and wraping it in a try brace lets it fail but continue. I’m probably missing the most obvious thing.

Does anyone have any idea why this maybe occuring? I had written this script a while ago and it worked perfectly fine then, and other scripts I have that write to DT sheets are still working. I’m stumped.

Thanks for getting this far!

I can only confirm the behaviour (macOS 12.5.1, DT 3.8.5) but cannot explain it.

I used the following script for confirmation:

tell application id "DNtp"
	set a to 1
	set b to 2
	set c to 3
	set d to 4
	set e to 5
	set f to 6
	set g to 7
	set h to 8
	set i to 9
	set j to 10
	set k to 11
	set l to 12
	set m to 13
	set n to 14
	set o to 15
	set doc_tsv to create record with {type:sheet, columns:{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o"}, name:"files"} in incoming group of database "test"
	set doc_tsv_cells to {} # cells of doc_tsv
	copy {a, b, c, d, e, f, g, h, i, j, k, l, m, n, o} to end of doc_tsv_cells
	copy {o, n, m, l, k, j, i, h, g, f, e, d, c, b, a} to end of doc_tsv_cells
	set cells of doc_tsv to doc_tsv_cells
end tell
1 Like

The cells property expects strings for each cell but the values are numbers in this case.

1 Like

and, once again, I can confirm that the error does not crop up when a to o are strings rather than numbers.

I just checked the code and actually DEVONthink should handle this but doesn’t anymore due to a bug. Fixed.

2 Likes

Amazing - thanks all. Thought I was going mad (as we’ve all felt I’m sure!) and I try not to ask simply explained errors here so had attempted most everything I could think of, though I’d not thought of the difference between strings and numbers.

1 Like

Nah, I’ve never felt you are going mad :crazy_face:

1 Like

You are a true wizard.

1 Like