Formatting output with showText? (add line breaks? output html?)

Hello community,

I’m just bought the tool today because I like the idea of make small extensions with javascript for it.

After installing it I tried to write the first extension. Thanks to the documentation I was able start very quickly.

Now I’m stuck formatting the output with popclip.showText().

My first thought was if it is possible to add line-breaks to the string? As an alternative it would be great if a HTML-output is possible.

Am I missing the correct function, or is there a way to archive this?


The screenshot shows my use-case. I want to show the length of the selected JSON-arrays or JSON-objects. In this case it would be great if I could output a list. (Ideally some nested

Welcome to the forum @8cuda .

No, the display with showText only shows one line and removes all the line breaks. There’s a maximum character limit too. It’s quite limited.

It would be nice to enhance this some time, but for now you are stuck with the one line.

2 Likes

Thanks @nick for the quick and honest answer. Thumbs up for the effort in supporting and maintaining the application over the years.

May I ask what the limitations were that led to the result that the showText() function is this limited.

Would it be a viable option to enhance it by passing an array of strings to showText()? So that each string in the array is an separate line in the popup-window?

Do you think that it’s possible make something like an showHtml() function? Or is this out the scope of this application?

May I ask what the limitations were that led to the result that the showText() function is this limited.

Simply that the code that displays the “showText” result is the same code that displays the PopClip pop-up itself. Indeed, the showText bubble is actually just a regular PopClip bar with one big a greyed-out button. And that code can only display one line of buttons.

Would it be a viable option to enhance it by passing an array of strings to showText()? So that each string in the array is an separate line in the popup-window?

Potentially. If I did it would be part of an overall re-write of the PopClip pop-up display & interaction capabilities. The actual PopClip bar display & button handling is actually the oldest part of the codebase. It would require a significant re-write of some core code so probably not any time soon. I’m quite conservative about feature additions and code changes. I don’t like to just bolt features on without deep consideration of how it factors in to to the usability, maintainability, simplicity and cohesiveness of the app.

Do you think that it’s possible make something like an showHtml() function? Or is this out the scope of this application?

I won’t say no! All this is great stuff. But, I’m just one person, just working on one thing at a time. I never promise features but I always listen to and think about the ideas people share. A lot of the best stuff in PopClip has come from user suggestions. So do keep on sharing your suggestions even if I do say “no” and “not yet” a lot :slight_smile:

2 Likes

Yeah - thanks for the detailed answer.

I’m a developer myself and I totally get your point. Especially when the showText is just a modified-version of the basic-popup ‘kind a hack’.

With such an grown application its tricky to change stuff without potentially breaking things.

I like and support this approach!

Quick update and a question.

Seems that the line-breaks could easily be archived with AppleScript.

The question is now if there is a way to call javaScript first and then give the result to appleScript?


#popclip - classic YAML snippet
name: Sample AppleScript Dialog
icon: Hi!
applescript: |
  set theDialogText to "The \n curent \n date \n and time is " & (current date) & "."
  display dialog theDialogText
1 Like

Unfortunately not but I’d like to add that to the JS API i.e.popclip.runAppleScript("<my script here>") or similar.

So far JS in PopClip is very secure environment and can’t access anything outside its own sandbox. The only current exception is if you add the network entitlement JS can access the internet.

But in general I think all the other action types that PopClip can do should be callable from JavaScript.

To do this I would add a new entitlements: [applescript] or similar, since now the JS will be able to break out of its secure sandbox.

Definitely under strong consideration.

1 Like

I have a work around for showing a text value on the screen.

If you don’t mind, you can install Snipaste and set the hot key to “command option control A”, and then, you can use the JavaScript to trigger the key press event:

  popclip.copyText(popclip.input.text)
  popclip.pressKey('command option control A')

I’m not sure why I could not trigger the default hot key F3 in popclip. And I’m not sure if you can trigger the AppleScript with hot key.

1 Like

Thanks, great tip @NightBack and welcome to the forum.

Regarding F3, popclip.pressKey('f3') ought to work in general, but the way apps detect hotkeys can vary, and some apps will not detect PopClip’s presses. (For example, BetterTouchTool can’t see PopClip’s keypresses.)

On a related note: is there currently a way to interact with Stickies.app in javascript extensions? I’d like to directly send the results from ChatGPT extension to a new sticky note.

1 Like

On a related note: is there currently a way to interact with Stickies.app in javascript extensions?

At the moment, no. JavaScript extensions are completely siloed.

I have encountered the same problem. Have you found a suitable solution yet?

Same issue, any other workaround ?