Cocoa Services Programming - How to identify whether the selected item is a folder or file wih NSFi

Posted by rockybalboa on Stack Overflow See other posts from Stack Overflow or by rockybalboa
Published on 2010-03-12T03:47:11Z Indexed on 2010/03/13 9:25 UTC
Read the original article Hit count: 303

Filed under:

Hi , I have some queries regarding Services menu validation . I would like to enable different services provided by my app based on whether a file or folder is selected in the Finder.

I have set NSFilenamesPboardType as the send type for the services . I have gone through the - (id)validRequestorForSendType:(NSString *)sendType returnType:(NSString *)returnType method but my issue is that the validation there seems to be done based on the sendType and return type. In my case , the selected file and folder pasteboard type is the same and I cannot determine whether the selected item in the Finder is a file or folder during the validation process ( This is before the actual service gets invoked i.e when the services menu is being shown to the user ) ?

So my question is that is there any way I can get some info about the selected item in the Finder and validate the different service menus offered by my application based on some info regarding the item rather than the basic validation of the send and return types ?

I am not able to find out any manner to do so but "Folder Actions" service in Snow Leopard gets enabled only for folders so it can be done. I did a /System/Library/CoreServices/pbs -dump_pboard and it is using a NSFilenamePBoardType also yet manages to activate only for folders.

Thanks in advace for any help .

© Stack Overflow or respective owner

Related posts about cocoa