SwiftAutomation icon indicating copy to clipboard operation
SwiftAutomation copied to clipboard

typeChar edge case

Open ronzo99 opened this issue 4 years ago • 0 comments

Finder has a "comment" property, which can be seen in Get Info for a folder, for example, or in SwiftAutomation: print("comment: \"\(try finder.folders["TEMP"].comment.get())\"")

If there is a comment, the descriptorType is utxt and is printed correctly. But if the comment is empty, the descriptorType is typeChar and SA prints comment: "<ScalarDescriptor "TEXT" ...>"

One way to fix: In unpackAsAny change case typeUTF16ExternalRepresentation, typeUnicodeText: to case typeUTF16ExternalRepresentation, typeUnicodeText, typeChar:

Then, in unpackAsString add this case:

case typeChar:
	guard let result = String(data: descriptor.data, encoding: .macOSRoman) else { throw AppleEventError.corruptData }
	return result

NOTE: I'm running this on Mojave, so regarding the question posed in the comment on the above line, "what, if any, macOS apps still use them", one answer is Finder (at least on Mojave 10.14.6). NOTE: I have since confirmed that this is still the case on Big Sur 11.4

ronzo99 avatar Jun 16 '21 16:06 ronzo99