Re: Handling of paths through sandbox
On Feb 12, 2020, at 08:56 , Gabriel Zachmann wrote: > > So rather than having the last part being chopped off (which is the important > part), > I would like to remove the beginning of the path, since that is unimportant. For partial paths, you can try converting the URLs to URLComponents, then constructing a relative URL whose base URL is the directory you searched in. That might give you a relative path that you can display. If that doesn’t give a suitable result, you’ll have to do a bit of work, but not much. Starting from a file URL, starting taking the last component of the URL (property “lastPathComponent”), and building it up into a path string. Keep removing the last component until the shortened URL equals the pictures directory. That’s a bit hand-wavy on the details, but it shouldn’t be too hard to code. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Handling of paths through sandbox
>> >> The problem is that the path names can get very long. >> And I am going to show them to the user. > > There is support in AppKit for displaying file paths to the user. > Unfortunately it's been I guess I should have said that I display the paths as a simple text overlay in my screensaver while it is running (and displaying images). Best regards, Gabriel ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Handling of paths through sandbox
> On Feb 12, 2020, at 8:56 AM, Gabriel Zachmann via Cocoa-dev > wrote: > > The problem is that the path names can get very long. > And I am going to show them to the user. There is support in AppKit for displaying file paths to the user. Unfortunately it's been long enough since I used it that I can't remember what it's called :-p Hopefully someone else remembers? > So rather than having the last part being chopped off (which is the important > part), > I would like to remove the beginning of the path, since that is unimportant. Generally you'd truncate the middle of the path, since the beginning of the path can be very important. —Jens ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Handling of paths through sandbox
Thanks a lot for your response. >> Problem is that I can't just do >> >> [ array_with_all_images addObject: [path substringFromIndex: ([dir_to_scan >> length] + 1)] ]; > > What is this supposed to be an array of? File names? Partial paths underneath > ~/Pictures? Exactly. The problem is that the path names can get very long. And I am going to show them to the user. So rather than having the last part being chopped off (which is the important part), I would like to remove the beginning of the path, since that is unimportant. Best regards, Gabriel > If the latter, why get partial paths at all, why not just make an array of > URLs? > > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Handling of paths through sandbox
On Feb 11, 2020, at 09:00 , Gabriel Zachmann via Cocoa-dev wrote: > > I have a question regarding the proper handling of paths under Catalina, > some of which go through the Container, some don't. > > More specifically, I get the Pictures folder using this line of code: > > dir_to_scan = [NSHomeDirectory() stringByAppendingPathComponent: > @"Pictures/"] Well, don’t do that. :) Instead, use one of the two NSFileManager methods that find the Pictures directory for you: URLsForDirectory:inDomains: URLForDirectory:inDomain:appropriateForURL:create:error: (You can specify nil for the “appropriateForURL” parameter.) Specify NSPicturesDirectory for the directory parameter, and NSUserDomainMask for the domain. Note that the documentation says you can use URLs in the query’s search scopes, so you don’t need to convert to paths at all. > This gives me a path like > /Users/zach/Library/Containers/com.apple.ScreenSaver.Engine.legacyScreenSaver/Data/Pictures > EXCEPT, apparently, Spotlight gives me paths starting with > /Users/zach/Pictures ! > (which does make some sense.) Yes, some of the items in the container, which are named as if they are standard directories, are actually symbolic links to the real directories outside the container. > Problem is that I can't just do > > [ array_with_all_images addObject: [path substringFromIndex: ([dir_to_scan > length] + 1)] ]; What is this supposed to be an array of? File names? Partial paths underneath ~/Pictures? If the latter, why get partial paths at all, why not just make an array of URLs? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com