How to make a “type class” of value zero (four bytes of 0)

(Thomas Tempelmann) #1

I need to pass an OSType with four zero bytes to my app. Like

«class XXXX»

But with NUL chars in place of the X chars.

See also: https://stackoverflow.com/questions/55880787

0 Likes

(Shane Stanley) #2

My guess is that it’s not possible/illegal.

0 Likes

(Thomas Tempelmann) #3

It’s possible with ASObjC. Someone one StackOverflow suggested:

use framework "Foundation"
set zeroType to (current application's NSAppleEventDescriptor's descriptorWithTypeCode:0) as any

And that works for my needs.

Now I finally have a script to extract all images from a clipping into new separate image clippings in iClip. Yay!

Thanks for all the help, Shane.

0 Likes

(Shane Stanley) #4

The any class is undefined, and it’s probably not a good idea to use it. You’d be better off using something like this:

use framework "Foundation"
set zeroType to item 1 of ((current application's NSArray's arrayWithObject:(current application's NSAppleEventDescriptor's descriptorWithTypeCode:0)) as list)
1 Like

(Thomas Tempelmann) #5

The SO answer suggested “… as anything”, which got turned into “as any” for me. Can’t make sense of it but will heed your proposal.

0 Likes

(Thomas Tempelmann) #6

BTW, this forum software is most excellent. Also works very well on an iPhone.

0 Likes

(Thomas Tempelmann) #7

CJK on SO suggested this alternative, that seems to work for me as well:

set zeroType to (current application's NSAppleEventDescriptor's descriptorWithTypeCode:0) as type class

Do you approve?

0 Likes

(Shane Stanley) #8

There are potential synonym issues. For example, that compiles to simply as type in Script Debugger.

(The problem with any is that it’s actually defined by Script Debugger, so it won’t compile in Script Editor.)

So if it were me, I’d play safe.

1 Like