• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Trying to get folder path of a Finder window (Applescript anyone?)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trying to get folder path of a Finder window (Applescript anyone?)


  • Subject: Re: Trying to get folder path of a Finder window (Applescript anyone?)
  • From: has <email@hidden>
  • Date: Wed, 16 May 2007 20:05:36 +0100

Giovanni Donelli wrote:

I would like to get from the Finder the list of the windows
(folder) opened and their relative path.

Using objc-appscript <http://appscript.sourceforge.net/objc- appscript.html>:


/*
 * To generate glue: osaglue FN Finder
 */
#import <Foundation/Foundation.h>
#import "FNGlue.h"

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    FNApplication *finder;
    NSArray *windowNames, *folderRefs;
    NSEnumerator *enumerator;
    FNReference *folderRef;
    NSURL *folderURL;

    finder = [[FNApplication alloc] initWithName:@"Finder.app"];

    // Get window names:
    windowNames = [[[[finder FinderWindows] name] get] send];
    NSLog(@"%@", windowNames);

// Get window folders:
/*
* In theory, this should be a one-liner:
* NSArray *urls = [[[[[finder FinderWindows] target] get]
* requestType: [ASConstant fileURL]] send];
* There's a couple of gotchas though; see below.
*/


/* 1. Some Finder windows (e.g. search windows) don't have a valid target
* reference, so we have to convert folder references to typeFileURL one at
* a time, ignoring any coercion errors due to invalid references.
*/
folderRefs = [[[[finder FinderWindows] target] get] send];
enumerator = [folderRefs objectEnumerator];
while (folderRef = [enumerator nextObject]) {
/*
* 2. Finder's get command doesn't recognise typeFileURL as a request
* type, so ask it for typeAlias then coerce to typeFileURL locally.
*/
folderURL = [[[[folderRef get] requestType:[ASConstant alias]]
resultType:typeFileURL] send];
// Note: folderURL will be null for invalid references.
NSLog(@"%@", folderURL);
}


    [finder release];
    [pool release];
    return 0;
}

HTH

has
--
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org
http://appscript.sourceforge.net/objc-appscript.html

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Prev by Date: Re: NSPopUpButtonCell -- I need an outlet to gain access to the button
  • Next by Date: Re: French number localization problem
  • Previous by thread: Re: French number localization problem
  • Next by thread: Generation of a Waveform
  • Index(es):
    • Date
    • Thread