Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: hs.styledtext.new() support for link attribute #3708

Open
von opened this issue Oct 24, 2024 · 1 comment
Open

Feature request: hs.styledtext.new() support for link attribute #3708

von opened this issue Oct 24, 2024 · 1 comment

Comments

@von
Copy link
Contributor

von commented Oct 24, 2024

Short version: I'd like to be able to use hs.styledtext.new() to create some styled text which is a hyerperlink but that function doesn't seem to respect the link attribute.

Details:

If I copy some hyperlinked text into the pastebuffer outside of Hammerspoon and then examine it, I see the link attribute in play:

<copy hyperlink into pastebuffer>

> st = hs.pasteboard.readStyledText()

> stt = st:asTable()

> i(stt)
{ "pertinax aliquando an", {
    attributes = {
      color = {
        __luaSkinType = "NSColor",
        alpha = 1.0,
        blue = 0.75433194637299,
        green = 0.23714117705822,
        red = 0.061691254377365
      },
      <snip>
      link = {
        __luaSkinType = "NSURL",
        url = "https://photos.google.com/"
      },
      <snip> 
      strokeWidth = 0.0,
      underlineStyle = 1.0
    },
    ends = 21,
    starts = 1
  },
  __luaSkinType = "NSAttributedString"
}

But if I try to use hs.styledtext.new() to create a hyperlink, the link attribute seems to be ignored:

> st = hs.styledtext.new("test string", { color = { __luaSkinType = "NSColor", alpha = 1.0, blue = 0.75433194637299, green = 0.23714117705822, red = 0.061691254377365 }, link = { __luaSkinType = "NSURL", url = "https://photos.google.com/" } })

> i(st:asTable())
{ "test string", {
    attributes = {
      color = {
        __luaSkinType = "NSColor",
        alpha = 1.0,
        blue = 0.75433194637299,
        green = 0.23714117705822,
        red = 0.061691254377365
      }
    },
    ends = 11,
    starts = 1
  },
  __luaSkinType = "NSAttributedString"
}

Since the hs.styledtext documentation doesn't mention link being supported, I assume the above behavior is not a bug and hence this is a new feature request.

@von
Copy link
Contributor Author

von commented Nov 2, 2024

I found the following work around: create the hyperlinked text using html and then covert it to styledtext using getStyledTextFromData().

stext = hs.styledtext.getStyledTextFromData('<a href="https:www.mit.edu">Test text</a>', "html")
hs.pasteboard.writeObjects(stext)

I also found some ways to do it using system calls as well (e.g.).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant