Cocoa - Open file package in Finder

I am trying to open Finder in a specific package.

I got this file, Example.backup, which is just a folder with the extension. In the search device, you can right-click (Show package contents) and the files will be presented to me. (the folder with the contents is missing).

I tried to open it using NSWorkspace methods, but none of them opened finder in this directory, they either select a file or open it using a related program.

Is there a way to do this in AppleScript maybe? Or Cocoa?

thank

+3
source share
1 answer

Since no one has answered yet, there may not be a one-line solution.

, , : call/usr/bin/open -R, Finder. , , ( ).

: ( ), Finder .

NSString *pathToBundle = @"/tmp/test.app";
NSFileManager *fm = [[[NSFileManager alloc] init] autorelease];

// get the last file/directory in the package
// TODO: error handling / empty package
NSString *lastItemInBundle = [[fm contentsOfDirectoryAtPath:pathToBundle error:NULL] lastObject];

// reveal this file in Finder, by using /usr/bin/open
// see -R option in the manpage
NSTask *open = [[[NSTask alloc] init] autorelease];
[open setLaunchPath:@"/usr/bin/open"];
[open setCurrentDirectoryPath:pathToBundle];
[open setArguments:[NSArray arrayWithObjects:@"-R", lastItemInBundle, nil]];
[open launch];
+2

Source: https://habr.com/ru/post/1770599/


All Articles