Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8315207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:04:49+00:00 2026-06-08T21:04:49+00:00

After trying for two months I find out how to obtain AttributedString from any

  • 0

After trying for two months I find out how to obtain AttributedString from any text range of TextEdit (or any NSTextView). my code is as:

AXUIElementRef systemWideElement = AXUIElementCreateSystemWide();
AXUIElementRef focussedElement = NULL;
AXError error = AXUIElementCopyAttributeValue(systemWideElement,
    kAXFocusedUIElementAttribute, (CFTypeRef*)&focussedElement);
if (error != kAXErrorSuccess) {
    println("Could not get focussed element");
}
else {
    AXValueRef selectedRangeValue = NULL;
    AXError getSelectedRangeError =
        AXUIElementCopyAttributeValue(focussedElement,
        kAXSelectedTextRangeAttribute, (CFTypeRef*)&selectedRangeValue);
    if (getSelectedRangeError == kAXErrorSuccess) {
        CFRange selectedRange;
        AXValueGetValue(selectedRangeValue, kAXValueCFRangeType,
            &selectedRange);
        AXValueRef attributedString = NULL;
        AXError getAttrStrError =
            AXUIElementCopyParameterizedAttributeValue(focussedElement,
            kAXAttributedStringForRangeParameterizedAttribute, selectedRangeValue,
            (CFTypeRef*)&attributedString);
        CFRelease(selectedRangeValue);

        if (getAttrStrError == kAXErrorSuccess)
        {
            CFAttributedStringRef attrStr = (CFAttributedStringRef)attributedString;

            CFTypeRef value = CFAttributedStringGetAttribute(
                attrStr, 0, kAXFontTextAttribute, NULL);

            println("value: %X", value); // value is not NULL, but I can't obtain font name from it.

            CFRelease(attributedString);
        }
        else
        {
            println("Could not get attributed string for selected range");
        }
    }
    else {
        println("Could not get selected range");
    }
}
if (focussedElement != NULL)
    CFRelease(focussedElement);
CFRelease(systemWideElement);

I properly obtained CFAttributedStringRef (I can get length or plain text from it), but I can not obtain font name.

Note:

the value returned form below code is not NULL:

CFTypeRef value = CFAttributedStringGetAttribute(
                attrStr, 0, kAXFontTextAttribute, NULL);

The value can not be assumed as CTFontRef or CGFontRef, ATSFontRef, … (causes exception).

Also I try kCTFontAttributeName instead kAXFontTextAttribute, but returns NULL.

Thanks a lot.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:04:50+00:00Added an answer on June 8, 2026 at 9:04 pm

    The value associated with the key kAXFontTextAttribute seems to be a CFDictionaryRef. See AXTextAttributedString documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to connect to a database with two tables. However, after I
After trying out VS2010b2 also my VS2008 installation changes the versions of solution and
After trying to figure out why a Capistrano task (which tried to start a
I am trying to set two databases. After lunch the emulator, and trying to
i trying to get two date from two calender with jquery how can i
I'm trying to compare two millisecond values in Java. One from a calendar, and
So what I'm trying to do is select all the distinct months from my
I'm trying to link two gestures one after another. UILongPressGestureRecognizer, then UIPanGestureRecognizer. I want
After much searching trying to find the best solution to using an embedded DB
Just a non-critical question that has bothered me after trying to find answers in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.