objective c - How to retrieve the list of selecetd files, from finder, efficiently, in a cocoa app? -
from within cocoa app, trying retrieve list of files have been selected in finder window. have found following way it, unbearably slow.
finderapplication * finder = [sbapplication applicationwithbundleidentifier:@"com.apple.finder"]; sbelementarray * selection = [[finder selection] get]; nsuinteger count = [selection count]; nsarray * items = [selection arraybyapplyingselector:@selector(url)]; nsmutablearray *filepaths =[[nsmutablearray alloc] init]; (nsstring * item in items) { nsurl * url = [nsurl urlwithstring:item]; [filepaths addobject:[url path]]; }
the expensive call, time wise,
sbelementarray * selection = [[finder selection] get];
the method literally hangs long times when selection made on large number of files, doesnt perform when working small selection either.
is there better way urls of selected files in foremost finder window?
i need have file urls can perform actions on/with files.
any appreciated!
thank you
you can use apple script
tell application "finder" selection end tell
or
osascript -e "tell application \"finder\" return selection"
Comments
Post a Comment