Re: NSAppleScript - what is going on here?
On Mar 23, 2009, at 12:19 AM, Adam R. Maxwell wrote: Using the MDItem C API had none of the AppleScript/Apple event problems, and was a small fraction of the code. On the other hand, MDItem will probably fail if the file is on a volume for which Spotlight is disabled or its index isn't up-to-date. --Michael ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSAppleScript - what is going on here?
On Mar 23, 2009, at 6:28 AM, Michael Tsai wrote: On Mar 23, 2009, at 12:19 AM, Adam R. Maxwell wrote: Using the MDItem C API had none of the AppleScript/Apple event problems, and was a small fraction of the code. On the other hand, MDItem will probably fail if the file is on a volume for which Spotlight is disabled or its index isn't up-to-date. Thanks for pointing that out; I just wrote a quick test and it does fail on my iDisk. Good thing I don't need it now that NSFileManager doesn't strip Finder comments... If anyone wants the Apple event version, let me know and I'll dig it up from svn history; it's an order of magnitude faster than using AppleScript. smime.p7s Description: S/MIME cryptographic signature ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSAppleScript - what is going on here?
On Sat, 21 Mar 2009 12:38:11 -0500, Steve Cronin steve_cro...@mac.com said: Folks; I'm trying to get a string value back from a simple AppleScript in Cocoa: NSDictionary *errorDict= nil; NSAppleScript *appleScriptObject = [[NSAppleScript alloc] initWithSource:theScript]; NSAppleEventDescriptor *eventDescriptor = [appleScriptObject executeAndReturnError: errorDict]; [appleScriptObject release]; if (([eventDescriptor descriptorType]) (errorDict==nil)) { return [self stringFromAppleEventDescriptor:eventDescriptor]; //my own method that checks descriptorType and returns stringValue } else { NSLog(@%@,[errorDict objectForKey:@NSAppleScriptErrorMessage]); return nil; } The 'theScript' is a valid script that executes flawlessly in 'Script Editor': tell application Finder try comment of file (/Users/steve/ as POSIX file) on error return Error end try end tell The problem is that the above errors out @ [appleScriptObject executeAndReturnError: errorDict]; The stack is shown below. That's hard to answer because you're so obviously lying. You are not reporting what you're really doing. What is theScript really? A string? Show us the string. And clearly you are not really saying /Users/steve/, so show us what you *are* saying. Let me show you how to answer. Here is a *complete* valid chunk of *real* Objective-C code: NSString* theScript = @tell application \Finder\\n @try\n @set pp to \/Users/mattneub/Desktop/BrahmsHandel2.mus\\n @comment of file (pp as POSIX file)\n @on error\n @return \Error\\n @end try\n @end tell\n; NSDictionary *errorDict= nil; NSAppleScript *appleScriptObject = [[NSAppleScript alloc] initWithSource:theScript]; NSAppleEventDescriptor *eventDescriptor = [appleScriptObject executeAndReturnError: errorDict]; [appleScriptObject release]; if (([eventDescriptor descriptorType]) (errorDict==nil)) { NSLog(@%@, [eventDescriptor stringValue]); } else { NSLog(@%@,[errorDict objectForKey:@NSAppleScriptErrorMessage]); } I actually ran that code and it actually works (the finder comment from the specified file appears in the log). Okay, now it's your turn. :) m. -- matt neuburg, phd = m...@tidbits.com, http://www.tidbits.com/matt/ A fool + a tool + an autorelease pool = cool! AppleScript: the Definitive Guide - Second Edition! http://www.tidbits.com/matt/default.html#applescriptthings ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSAppleScript - what is going on here?
Matt; I really take offense at your tone. I was not lying. I merely clipped out my personal details in order not to provide them to the world. The 'theScript' IS a string - constructed in ObjC differently than you show but a string nonetheless. Turns out the error was that an SDEF file had been renamed. As Samuel Jackson said in Black Snake Moan -- Collar that dog!, Steve On Mar 22, 2009, at 12:05 PM, Matt Neuburg wrote: On Sat, 21 Mar 2009 12:38:11 -0500, Steve Cronin steve_cro...@mac.com said: Folks; I'm trying to get a string value back from a simple AppleScript in Cocoa: NSDictionary *errorDict= nil; NSAppleScript *appleScriptObject = [[NSAppleScript alloc] initWithSource:theScript]; NSAppleEventDescriptor *eventDescriptor = [appleScriptObject executeAndReturnError: errorDict]; [appleScriptObject release]; if (([eventDescriptor descriptorType]) (errorDict==nil)) { return [self stringFromAppleEventDescriptor:eventDescriptor]; //my own method that checks descriptorType and returns stringValue } else { NSLog(@%@,[errorDict objectForKey:@NSAppleScriptErrorMessage]); return nil; } The 'theScript' is a valid script that executes flawlessly in 'Script Editor': tell application Finder try comment of file (/Users/steve/ as POSIX file) on error return Error end try end tell The problem is that the above errors out @ [appleScriptObject executeAndReturnError: errorDict]; The stack is shown below. That's hard to answer because you're so obviously lying. You are not reporting what you're really doing. What is theScript really? A string? Show us the string. And clearly you are not really saying /Users/ steve/, so show us what you *are* saying. Let me show you how to answer. Here is a *complete* valid chunk of *real* Objective-C code: NSString* theScript = @tell application \Finder\\n @try\n @set pp to \/Users/mattneub/Desktop/BrahmsHandel2.mus\\n @comment of file (pp as POSIX file)\n @on error\n @return \Error\\n @end try\n @end tell\n; NSDictionary *errorDict= nil; NSAppleScript *appleScriptObject = [[NSAppleScript alloc] initWithSource:theScript]; NSAppleEventDescriptor *eventDescriptor = [appleScriptObject executeAndReturnError: errorDict]; [appleScriptObject release]; if (([eventDescriptor descriptorType]) (errorDict==nil)) { NSLog(@%@, [eventDescriptor stringValue]); } else { NSLog(@%@,[errorDict objectForKey:@NSAppleScriptErrorMessage]); } I actually ran that code and it actually works (the finder comment from the specified file appears in the log). Okay, now it's your turn. :) m. -- matt neuburg, phd = m...@tidbits.com, http://www.tidbits.com/matt/ A fool + a tool + an autorelease pool = cool! AppleScript: the Definitive Guide - Second Edition! http://www.tidbits.com/matt/default.html#applescriptthings ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSAppleScript - what is going on here?
On Mar 21, 2009, at 10:38 AM, Steve Cronin wrote: The 'theScript' is a valid script that executes flawlessly in 'Script Editor': tell application Finder try comment of file (/Users/steve/ as POSIX file) on error return Error end try end tell It sounds like you've solved your problem, but I'd just note that if you're only getting Finder comments, MDItem is faster and simpler: - (NSString *)commentForURL:(NSURL *)fileURL; { NSParameterAssert([fileURL isFileURL]); MDItemRef mdItem = NULL; CFStringRef path = (CFStringRef)[fileURL path]; NSString *theComment = nil; if (path (mdItem = MDItemCreate(CFGetAllocator(path), path))) { theComment = (NSString *)MDItemCopyAttribute(mdItem, kMDItemFinderComment); CFRelease(mdItem); [theComment autorelease]; } return theComment; } smime.p7s Description: S/MIME cryptographic signature ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSAppleScript - what is going on here?
Adam; I'm an ObjC guy -- I generally avoid the C stuff if possible - 'cause I have to support my own code. But your method seems like it will work not only as a replacement but actually a doorway to the full gamut of common metadata attributes - very nice!! I know I should lose the resistance but there are only so many mountains one guy can climb... Thanks for the very helpful note! Steve On Mar 22, 2009, at 12:43 PM, Adam R. Maxwell wrote: On Mar 21, 2009, at 10:38 AM, Steve Cronin wrote: The 'theScript' is a valid script that executes flawlessly in 'Script Editor': tell application Finder try comment of file (/Users/steve/ as POSIX file) on error return Error end try end tell It sounds like you've solved your problem, but I'd just note that if you're only getting Finder comments, MDItem is faster and simpler: - (NSString *)commentForURL:(NSURL *)fileURL; { NSParameterAssert([fileURL isFileURL]); MDItemRef mdItem = NULL; CFStringRef path = (CFStringRef)[fileURL path]; NSString *theComment = nil; if (path (mdItem = MDItemCreate(CFGetAllocator(path), path))) { theComment = (NSString *)MDItemCopyAttribute(mdItem, kMDItemFinderComment); CFRelease(mdItem); [theComment autorelease]; } return theComment; } ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSAppleScript - what is going on here?
On Sun, Mar 22, 2009 at 1:53 PM, Steve Cronin steve_cro...@mac.com wrote: I'm an ObjC guy -- I generally avoid the C stuff if possible - 'cause I have to support my own code. You cannot reasonably expect to avoid C... there's a lot of functionality Cocoa doesn't provide. Launch Services for example. You're only doing yourself a disservice by avoiding C APIs, which are just as much part of Objective-C as the OO stuff -- ObjC is a strict superset after all. I bet that by avoiding C you actually create more work for yourself than if you just went with C when appropriate. --Kyle Sluder ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSAppleScript - what is going on here?
On Mar 22, 2009, at 1:53 PM, Steve Cronin wrote: I'm an ObjC guy -- I generally avoid the C stuff if possible - 'cause I have to support my own code. Objective-C is a superset of C. Avoiding the C stuff isn't really possible - it is a core part of the language. As far as choice of API, I tend to be a pragmatist, choosing an appropriate tool for the task at hand, without artificial restrictions. JIm ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSAppleScript - what is going on here?
On Mar 22, 2009, at 8:54 PM, Michael Ash wrote: On Sun, Mar 22, 2009 at 1:53 PM, Steve Cronin steve_cro...@mac.com wrote: Adam; I'm an ObjC guy -- I generally avoid the C stuff if possible - 'cause I have to support my own code. In addition to what the others have said, avoiding the C stuff if possible but being perfectly happy to use *AppleScript*, of all languages, is completely bizarre. C may be somewhat tedious and unforgiving, but it doesn't come anywhere remotely close to the utter horribleness that is AppleScript. Indeed. Let me add that the MDItem code I posted was the 3rd iteration of that method. The first used NSAppleScript, but it took 0.5s to execute and caused a noticeable hiccup in the app. My second attempt used raw Apple events and executed in 0.01s, but would cause Finder to stall when it was called during a drag-and-drop targeting Finder (ISTR Finder's event loop was trying to process the Apple event and the drop event at the same time). Using the MDItem C API had none of the AppleScript/Apple event problems, and was a small fraction of the code. Once you get used to working with CF, it's really no harder than Obj-C, and gives you more tools to choose from. -- Adam smime.p7s Description: S/MIME cryptographic signature ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
NSAppleScript - what is going on here?
Folks; I'm trying to get a string value back from a simple AppleScript in Cocoa: NSDictionary *errorDict= nil; NSAppleScript *appleScriptObject = [[NSAppleScript alloc] initWithSource:theScript]; NSAppleEventDescriptor *eventDescriptor = [appleScriptObject executeAndReturnError: errorDict]; [appleScriptObject release]; if (([eventDescriptor descriptorType]) (errorDict==nil)) { return [self stringFromAppleEventDescriptor:eventDescriptor]; //my own method that checks descriptorType and returns stringValue } else { NSLog(@%@,[errorDict objectForKey:@NSAppleScriptErrorMessage]); return nil; } The 'theScript' is a valid script that executes flawlessly in 'Script Editor': tell application Finder try comment of file (/Users/steve/ as POSIX file) on error return Error end try end tell The problem is that the above errors out @ [appleScriptObject executeAndReturnError: errorDict]; The stack is shown below. What am I overlooking here? Steve #0 0x9543c1ab in CFDataGetBytePtr #1 0x90462218 in XMLDataResolvingXIncludes #2 0x90464fa8 in OSACopyScriptingDefinition #3 0x90861531 in -[NSScriptSuiteRegistry loadSuitesFromBundle:] #4 0x90860ede in -[NSScriptSuiteRegistry _loadSuitesForAlreadyLoadedBundles] #5 0x90860bd4 in -[NSScriptSuiteRegistry init] #6 0x90860b44 in +[NSScriptSuiteRegistry sharedScriptSuiteRegistry] #7 0x908608d9 in +[NSScriptSuiteRegistry _loadScriptSuites] #8 0x907b7f1c in _nsnote_callback #9 0x954568da in __CFXNotificationPost #10 0x95456bb3 in _CFXNotificationPostNotification #11 0x907b5080 in -[NSNotificationCenter postNotificationName:object:userInfo:] #12 0x907be8c8 in -[NSNotificationCenter postNotificationName:object:] #13 0x90873650 in -[NSAppleEventManager(NSInternal) _sendDidFailToDispatchNotification] #14 0x90873574 in _NSAppleEventManagerPreDispatchHandler #15 0x952e9648 in aeDispatchAppleEvent #16 0x952f27be in AESendMessage #17 0x952f55ab in aeSend #18 0x957985af in AESend #19 0x01be917a in AEDefaultSendProc #20 0x01becdfd in ComponentSend #21 0x01becfc0 in SendSimpleEventWithReply #22 0x01bd4c3d in ScanForScriptingAdditions #23 0x01bd4f07 in ASInitLocal #24 0x01bd4fa5 in ASDefaultInit #25 0x01bcca2d in AppleScriptComponent #26 0x93fdda05 in CallComponentDispatch #27 0x90456af8 in OSASetActiveProc #28 0x01be86c4 in AGenericManager::UpdateInstanceProcs #29 0x01be87e2 in AGenericManager::ComponentFromSubtype #30 0x01be8915 in AGenericManager::DefaultComponentInstance #31 0x01be811c in AGenericCall::PreDelegate #32 0x01be88c9 in AGenericManager::HandleOSACall #33 0x93fdda05 in CallComponentDispatch #34 0x904681c3 in OSACompile #35 0x908a13b8 in -[NSAppleScript compileAndReturnError:] #36 0x908a16a6 in -[NSAppleScript(NSPrivate) _executeWithMode:andReturnError:] #37 0x908a1461 in -[NSAppleScript executeAndReturnError:] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSAppleScript - what is going on here?
On 2009 Mar 21, at 10:38, Steve Cronin wrote: What am I overlooking here? #0 0x9543c1ab in CFDataGetBytePtr #1 0x90462218 in XMLDataResolvingXIncludes #2 0x90464fa8 in OSACopyScriptingDefinition #3 0x90861531 in -[NSScriptSuiteRegistry loadSuitesFromBundle:] #4 0x90860ede in -[NSScriptSuiteRegistry _loadSuitesForAlreadyLoadedBundles] #5 0x90860bd4 in -[NSScriptSuiteRegistry init] Looks like maybe it's having trouble parsing your sdef file. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com