Re: Getting array of Item names and Positions
Re: Getting array of Item names and Positions
- Subject: Re: Getting array of Item names and Positions
- From: has <email@hidden>
- Date: Mon, 28 Jan 2008 17:32:43 +0000
On 28 Jan 2008, at 14:54, development2 wrote:
My current problem is, I need to find a way to get the file name and
desktop position of all items on the desktop. I have this script
which works (In a way):
tell application "Finder"
set names to name of items of desktop
set positions to desktop position of items of desktop
return {names, positions}
end tell
Two 'get' events - one to get all names, one to get all positions - is
as concise as you can get.
The problem is though that I can not guarantee that item 1 of the
name array corresponds to item one of the position array.
How so? Unless something on the desktop changes between the first and
second commands, the order should be the same in each case. Do you
have an example of it doing anything different?
Since you're in Cocoa, I'd suggest skipping AppleScript and just send
Apple events directly from ObjC. That way you can take advantage of
native Cocoa classes such as NSArray and NSEnumerator. e.g. Using objc-
appscript (see my sig for links):
// To create Finder glue: osaglue -o FNGlue -p FN Finder
#import "FNGlue.h"
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
FNApplication *finder;
FNReference *deskItems;
NSArray *names, *positions, *position;
NSEnumerator *enum1, *enum2;
NSString *name;
finder = [[FNApplication alloc] initWithBundleID: @"com.apple.finder"];
deskItems = [[finder desktop] items];
names = [[[[[finder desktop] items] name] get] send];
positions = [[[[[finder desktop] items] desktopPosition] get] send];
enum1 = [names objectEnumerator];
enum2 = [positions objectEnumerator];
while ((name = [enum1 nextObject]) && (position = [enum2 nextObject]))
NSLog(@"\nNAME: %@\nPOSITION: %@\n\n", name, position);
[finder release];
[pool drain];
return 0;
}
HTH
has
--
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden