1

I want to open a new Finder window of a specific size in a specific position and displaying a specific folder.

In ScriptingBridge (XCode 6, Mavericks 9.4) I can open a new Finder window and have figured out how to read the URL of the folder it opens. But I am really struggling with how to set the folder to something different.

I have tried to assign the window a 'target' SBObject initialised with a 'URL' property. but the URL property is readonly although 'target' seems not to be. I've used 'get' to ensure there is a FinderFolder object and a FinderFinderWindow object.

I've tried using a dictionary of properties with a URL key and creating a 'folder'.

FinderFolder *folder = [[[_finder classForScriptingClass:@"folder"] alloc]
    initWithProperties:dict];
[[_finder folders] addObject:folder]; 

I have read the Apple docs and looked for examples all over but cannot find an instance of someone assigning the folder path.

BickaSoft
  • 11
  • 3

2 Answers2

0
// open folder "Documents" of home folder
FinderFolder *theHomeFolder = [theFinder home];
NSLog(@"theHomeFolder: %@",theHomeFolder);

SBElementArray * theHomeFolderFolders = [theHomeFolder folders];
NSLog(@"theHomeFolderFolders: %@",theHomeFolderFolders);

FinderFolder *theDocsFolder = [theHomeFolderFolders objectWithName:@"Documents"];
NSLog(@"theDocsFolder: %@",theDocsFolder);

[theDocsFolder openUsing:nil withProperties:nil];
FinderFinderWindow * docsFolderWindow = (FinderFinderWindow*) [theDocsFolder containerWindow];
NSLog(@"docsFolderWindow: %@",docsFolderWindow);

docsFolderWindow = [docsFolderWindow get];
NSLog(@"docsFolderWindow: %@",docsFolderWindow);

// change its bounds
docsFolderWindow.bounds = NSMakeRect(64., 64., 800, 600.);

// other fun stuff…
[docsFolderWindow setCurrentView:FinderEcvwListView];
[[docsFolderWindow iconViewOptions] setArrangement:FinderEarrArrangedByName];
[docsFolderWindow cleanUpBy:@selector(name)];

docsFolderWindow.toolbarVisible = NO;
docsFolderWindow.statusbarVisible = NO;
docsFolderWindow.sidebarWidth = 0;
geowar
  • 4,397
  • 1
  • 28
  • 24
0

There are a few different ways. The other answer works, or you could explicitly make a new Finder window and set its target property:

NSURL *u = [NSURL fileURLWithPath:@"/tmp"];
FinderFinderWindow *w = [[[theFinder classForScriptingClass:@"Finder window] alloc] init];
[[theFinder finderWindows] addObject:w];
[w setTarget:u];

You could also set it to an SBObject referring to a Finder item, such as theDocsFolder from the other answer.

Chris N
  • 905
  • 5
  • 10