Request for a new token: %CompositeTextWidth%

You would need to couple the above with JavaScript for a bullet proof implementation. JavaScript could determine the exact size of your text container and the exact pixel dimensions of your string and do the dirty work.

Like I said, it's a deep dive if you're new to the language(s). If you post your working prototype (or even a much more detailed explanation of what you're shooting for) I'd be glad to see if I could point you in the right direction. Here's some further reading on fitting text using a combination of tech.

If Javascript can get the exact pixel dimensions of the string that was output, then Javascript could be a solution. But most of those examples that you showed me do NOT get the pixel dimensions of the outputted text. They just cheat, which I can do well enough without examining their code. I am very good at creating algorithms that cheat to get approximate results.

MAGICNUMBER - is just an approximator
FITTEXT - is just an approximator, and requires additional software called jquery to work
TEXTFIT - is just an approximator
FITTY - might work, can't be sure, no video demos to see, I may need to download it
TEXTFILL - might work, can't be sure, no video demos to see, but requires additional software
FLOWTYPE - does not scale the text to fit the box, it just scales the text as a function of box size
SVG - no URL was provided, so I can't tell how it works, but it claims to require magic numbers

I truly appreciate your tips and your knowledge. But when I visited the websites and, in some cases, found videos or simulators of the javascript in action, the videos made it clear that they don't do what I want. My requirement is to get text that ALWAYS fits in its box. If you don't know what I mean, try using Keynote and experiment with its "Shrink to Fit" option. Keynote does precisely what I want, while these routines, at least most of them, don't.

There must be a system API that they use to obtain the width of the outputted text. How else could they possibly work if not through an API? Hopefully they aren't reading the pixels directly off the screen to see how the text was written. Do you know which API they would use or what the name of the API routine is?

There's no point in showing you my cheating code because it's not what I want anyway. I want something that isn't an approximator.

If Keynote can do it, it's doable. And I'm fairly sure it's done with the assistance of a macOS API. All I need to do is find out what that API is and then use a language that can access that API.

The nice video (GIF) you provided shows that that is definitely not what I want. The video shows that the scaling is very inaccurate resulting in a window that's sometimes 75% blank. I want an algorithm that shrinks to fit. And when I say "fit" I mean 100% fit, not 50% fit.

If you take a look at Keynote's "Shrink to Fit" you will see what I want. It works perfectly. That's what I want. I don't want approximations that are often 50% over-shrinking or 20% under-shrinking. I can write my own approximations using the built in actions in KM, so I certainly don't need Javascript to do that.

I am sorry if I sound frustrated. I know you're all trying to get me closer to a partial solution. And I appreciate that. But I've already got a half-baked solution. What I want is an actual real solution. That's why I suggested %CompositeTextWidth%. If there was such a token, I could write a solution that always came up with the correct answer. (Well, %CompositeTextHeight% would also be needed, but I didn't want to push my luck in my original post.)

@Sleepy oh I see, now I understood what you were talking about.

Hey there @Sleepy, I just happened upon this jQuery plugin and thought of you.
Might fit the bill (if you've not already found a solution).

1 Like

Rather than have Keyboard Maestro automagically interpret RTF as attributed strings, I have added explicit filters to convert Attributed Text (in clipboards) to/from RTF text for the next version.

3 Likes