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

  • Home
  • SEARCH
  • 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 7518203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:41:26+00:00 2026-05-30T01:41:26+00:00

I have a basic NSTextView with rich text and graphics enabled (in IB). What

  • 0

I have a basic NSTextView with rich text and graphics enabled (in IB). What I’d like to get is the path and filename of any images dragged in so I can pass those to another class.

I’m new to NSAttributedString but I’ve got a loop using enumerateAttributesInRange:options:usingBlock: looking for NSAttachmentAttributeName and that’s all working fine. But going deeper, I get to the fileWrapper class and it’s apparent inability to give me the path of the item.

How would I go about getting the name and path of the NSTextAttachment?

Related: Is there an easier way to get them all then stepping through the attributes?

Thanks much!

  • 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-05-30T01:41:29+00:00Added an answer on May 30, 2026 at 1:41 am

    While I personally hold the design of NSFileWrapper in contempt, if you just need the data of each attachment you can access it as an NSData instance via NSFileWrapper’s regularFileContents method. However, I needed a valid and explicit pathname to the attachment for my application. To get it is much more work than it should be:

    You can subclass your NSTextView and override the NSDraggingDestination Protocol method draggingEntered: and you can traverse the NSPasteboardItem objects passed to your application during the dragging operation. I chose to keep the pathname and its inode number in an NSMutableDictionary, as NSFileWrapper can provide you with the inode of the referenced file. Later, when I access the NSTextView contents via an NSAttributedString, I can fetch the pathname of an attachment using the inode as an index.

    - (NSDragOperation)draggingEntered:(id < NSDraggingInfo >)sender {
    
        // get pasteboard from dragging operation
    
        NSPasteboard *pasteboard = [sender draggingPasteboard];
    
        NSArray *pasteboardItems = [pasteboard pasteboardItems];
    
        for ( NSPasteboardItem *pasteboardItem in pasteboardItems ) {
    
            // look for a file url type from the pasteboard item
    
            NSString *draggedURLString = [pasteboardItem stringForType:@"public.file-url"];
    
            if (draggedURLString != nil) {
    
                NSURL *draggedURL = [NSURL URLWithString:draggedURLString];
    
                NSString *draggedPath = [draggedURL path];
    
                NSLog(@"pathname: %@", draggedPath);
    
                // do something with the path
    
                // get file attributes
    
                NSDictionary *draggedAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:draggedPath error:nil];
    
                if ( draggedAttributes == nil)
                    continue;
    
                // the NSFileWrapper allows access to the absolute file via NSFileSystemFileNumber
                // put the path and the inode (returned as an NSNumber) into a NSMutableDictionary 
    
                NSNumber *draggedInode = [draggedAttributes objectForKey:NSFileSystemFileNumber];
    
                [draggedFiles setObject:draggedPath forKey:draggedInode];
            }
    
        }
    
        return [super draggingEntered:sender];
    }
    

    One issue with my solution, that doesn’t effect my application, is that multiple files dragged into the view (either singly or together) which are hard links to the same file, will only be indexed as the last pathname added to the dictionary which shares the inode. Depending on how the pathnames are utilized by your application this could be an issue.

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

Sidebar

Related Questions

I have basic CSS experienced so I would like to know how can I
I have a basic C# console application that reads a text file (CSV format)
I have a basic quiz/survey type application I'm working on, and I'd like to
I have basic stored procedure that performs a full text search against 3 columns
I have basic idea about running PHP in different configurations like mod_php, cgi, FastCGI,
I have Basic Authorization mechanism on the server for WSDL/SOAP. How I can send
It seems like most of the messaging systems I've looked at have basic, if
I have an NSTextView with an NSTableView in a window. I'd like to be
Possible Duplicate: How to remove the text in progressBar in Android? I have basic
I have basic *.xib file, which have NSView. How can I use another nib

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.