Re: Opening an external file in a external application
John Love wrote: Really though, what's best/practical/possible all depends on what you're trying to do, so if you want more advice then you'll need to provide more information. Very short info list is as follows (stuff I need to do from within my Cocoa app): 1) be able to save the Excel spreadsheet Opening and saving Excel workbooks can be done with Apple events, e.g. using objc-appscript [1]: // To create glue: osaglue -o MEGlue -p ME Microsoft Excel MEApplication *microsoftExcel = [MEApplication applicationWithName: @"Microsoft Excel"]; // open file specified by HFS path MEOpenWorkbookCommand *cmd = [[microsoftExcel openWorkbook] workbookFileName: @"Mac HD:Users:foo:Workbook1.xlsx"]; id result = [cmd send]; // result is a by-name reference to the new workbook, or nil if an error occurred // save in new file MEReference *ref = [[microsoftExcel workbooks] byName: @"Workbook1.xlsx"]; MESaveWorkbookAsCommand *cmd = [[ref saveWorkbookAs] filename: @"Mac HD:Users:foo:Workbook2.xlsx"]; id result = [cmd send]; // result is nil if an error occurred Two potential problems to be aware of: 1. Excel stupidly uses HFS path strings in its 'open workbook' and 'save workbook as' commands. This means you'll have big problems if you have another volume with the same name as the one you're opening from/saving to, as HFS paths can't distinguish between identically named volumes. (Better designed applications use alias and file URL types to identify filesystem objects and locations.) You might be able to work around this issue by using the standard 'open' and 'save' commands, although you lose the additional features provided by 'open workbook' and 'save workbook as'. Or you may consider using HFS paths to be an acceptable risk and just put up with them. 2. References returned by Excel only identify workbook objects by- index or by-name references. That makes it tricky to ensure you've a stable handle on the workbook for the length of time it's open. (By- index specifiers are sensitive to element order; by-name specifiers can't distinguish between two elements with the same name. Only by-id specifiers are guaranteed to be unique and stable over a target process's lifetime, but most apps don't use those.) I did wonder if using a by-test specifier would work; something like: tell app "Excel" tell first workbook whose full name = HFS_path_to_file -- do stuff here end end but it doesn't work, so you'll either need to iterate over elements and compare their paths yourself or else just use the existing by-name references and trust that nobody opens another file with the same name while your program is doing its thing. 2) be able to stop any calculation in progress Dunno myself; you'll need to ask someone with more Excel scripting experience. 3) be able to detect if the user closed the spreadsheet "behind the back" of my Cocoa app, upon which my Cocoa app would raise a NSAlert. Assuming you've figured out a way to uniquely identify your workbook element, you could poll Excel at regular intervals to see if it still exists. HTH has [1] Be aware that Office apps are a rather eccentric bunch even by AppleScripting standards, but appscript's application compatibility is very nearly as good as AppleScript's these days (and sometimes even better) so I don't think it'll have any problems. -- Control AppleScriptable applications from Python, Ruby and ObjC: http://appscript.sourceforge.net ___ 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 [EMAIL PROTECTED]
Re: Opening an external file in a external application
- (BOOL)openURLs:(NSArray *)urls withAppBundleIdentifier:(NSString *)bundleIdentifier options: (NSWorkspaceLaunchOptions)optionsadditionalEventParamDescriptor: (NSAppleEventDescriptor *)descriptor launchIdentifiers:(NSArray **)identifiers Long method name, but you can pass in NSWorkspaceLaunchWithoutActivation as one of the options to avoid having the app come to the foreground (10.3+). On Aug 14, 2008, at 2:54 PM, John Love wrote: workSpace = [NSWorkspace sharedWorkspace]; success = [workSpace openURL:absoluteURL]; activates Excel .. what do I need to add to re-activate my Cocoa app .. "activate me" was terribly easy with AppleScript. NSApplication has methods to active your application. found it ... thanks! [NSApp activateIgnoringOtherApps:YES]; ... now back to (1,2,3) above John Love Touch the Future! Teach! Whoops ... almost ... activateIgnoringOtherApps momentarily activates my cocoa app. However, the application, Excel, keeps activating itself until it is the front application. So, I guess what I really need is a technique to determine when the app, Excel, is completely finished coming to the front and then calling activateIgnoringOtherApps. I really don't know how to do this because this "smells" of having to interrupt Cocoa's main event loop and that is a definite no-no. Maybe its a matter of asking Excel to notify "me" when it completes its startup. NSNotification?? ___ 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/nateweaver%40xtechllc.com This email sent to [EMAIL PROTECTED] ___ 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 [EMAIL PROTECTED]
Re: Opening an external file in a external application
workSpace = [NSWorkspace sharedWorkspace]; success = [workSpace openURL:absoluteURL]; activates Excel .. what do I need to add to re-activate my Cocoa app .. "activate me" was terribly easy with AppleScript. NSApplication has methods to active your application. found it ... thanks! [NSApp activateIgnoringOtherApps:YES]; ... now back to (1,2,3) above John Love Touch the Future! Teach! Whoops ... almost ... activateIgnoringOtherApps momentarily activates my cocoa app. However, the application, Excel, keeps activating itself until it is the front application. So, I guess what I really need is a technique to determine when the app, Excel, is completely finished coming to the front and then calling activateIgnoringOtherApps. I really don't know how to do this because this "smells" of having to interrupt Cocoa's main event loop and that is a definite no-no. Maybe its a matter of asking Excel to notify "me" when it completes its startup. NSNotification?? ___ 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 [EMAIL PROTECTED]
Re: Opening an external file in a external application
On Aug 13, 08, at 12:09 PM, Shawn Erickson wrote: On Aug 13, 2008, at 8:17 AM, John Love wrote: On 12 Aug 2008, has wrote: Really though, what's best/practical/possible all depends on what you're trying to do, so if you want more advice then you'll need to provide more information. Very short info list is as follows (stuff I need to do from within my Cocoa app): 1) be able to save the Excel spreadsheet 2) be able to stop any calculation in progress 3) be able to detect if the user closed the spreadsheet "behind the back" of my Cocoa app, upon which my Cocoa app would raise a NSAlert. Before I forget again, one question *not* related to the above, namely, the call within my overridden readFromURL: workSpace = [NSWorkspace sharedWorkspace]; success = [workSpace openURL:absoluteURL]; activates Excel .. what do I need to add to re-activate my Cocoa app .. "activate me" was terribly easy with AppleScript. NSApplication has methods to active your application. found it ... thanks! [NSApp activateIgnoringOtherApps:YES]; ... now back to (1,2,3) above John Love Touch the Future! Teach! ___ 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 [EMAIL PROTECTED]
Re: Opening an external file in a external application
On Aug 13, 2008, at 8:17 AM, John Love wrote: On 12 Aug 2008, has wrote: Really though, what's best/practical/possible all depends on what you're trying to do, so if you want more advice then you'll need to provide more information. Very short info list is as follows (stuff I need to do from within my Cocoa app): 1) be able to save the Excel spreadsheet 2) be able to stop any calculation in progress 3) be able to detect if the user closed the spreadsheet "behind the back" of my Cocoa app, upon which my Cocoa app would raise a NSAlert. Before I forget again, one question *not* related to the above, namely, the call within my overridden readFromURL: workSpace = [NSWorkspace sharedWorkspace]; success = [workSpace openURL:absoluteURL]; activates Excel .. what do I need to add to re-activate my Cocoa app .. "activate me" was terribly easy with AppleScript. NSApplication has methods to active your application. ___ 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 [EMAIL PROTECTED]
Re: Opening an external file in a external application
On 12 Aug 2008, has wrote: Really though, what's best/practical/possible all depends on what you're trying to do, so if you want more advice then you'll need to provide more information. Very short info list is as follows (stuff I need to do from within my Cocoa app): 1) be able to save the Excel spreadsheet 2) be able to stop any calculation in progress 3) be able to detect if the user closed the spreadsheet "behind the back" of my Cocoa app, upon which my Cocoa app would raise a NSAlert. Before I forget again, one question *not* related to the above, namely, the call within my overridden readFromURL: workSpace = [NSWorkspace sharedWorkspace]; success = [workSpace openURL:absoluteURL]; activates Excel .. what do I need to add to re-activate my Cocoa app .. "activate me" was terribly easy with AppleScript. John ___ 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 [EMAIL PROTECTED]
Re: Opening an external file in a external application
has wrote: ... and don't forget stuff like OpenOffice which contain full-blown spreadsheet engines and Excel file importers/exporters. I'll make a plug for OpenOffice.org here. The 3.0 release for Mac OS X is going to be completely Aqua native with the interface done in Cocoa. This work is all done. OpenOffice.org also has a SDK that you can install. There is support for C++, Java, and StarBasic. The Java stuff is pretty much cross platform if your environment is setup properly. (There's a script to help with this.) Anyway, I've been working with the SDK using the 3.1 code. I'll check with Juergen if he thinks it will be usable for the 3.0 release which is due in a month or two. HtH, Jason ___ 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 [EMAIL PROTECTED]
Re: Opening an external file in a external application
On 13 Aug 2008, at 4:10 am, John Love wrote: I don't have much hope of that .. so what I probably need to focus on is how to display the Excel spreadsheet in my document window. Any ideas will definitely be very appreciated. The good news (of sorts) is that MS recently published most of the Office formats: http://www.microsoft.com/interop/docs/OfficeBinaryFormats.mspx The bad news is that they run to thousands of pages. Good luck... Graham ___ 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 [EMAIL PROTECTED]
Re: Opening an external file in a external application
John Love wrote: I still need to figure out if it is possible for Excel to communicate back to my app via some sort of NSNotification. Very much doubt it, though you always can try Tildesoft's Notification Watcher just to be sure. Depending on the sort of operation it is that you're wanting to monitor (i.e. if it's something that doesn't block the main event loop), you may be able to poll Excel via its Apple event interface; clumsy, but better than nothing. For more specific advice and suggestions, write up a complete description of what you need to do, and try asking on the AppleScript-users list as well as that's where most Excel scripters can be found. I don't have much hope of that .. so what I probably need to focus on is how to display the Excel spreadsheet in my document window. I suspect what you really want is Windows, where Office is a major embeddable application framework in itself. ;) Failing that, there are third-party Excel parsers around for various language if all you want to do is display the spreadsheet post- processing, and don't forget stuff like OpenOffice which contain full- blown spreadsheet engines and Excel file importers/exporters. Really though, what's best/practical/possible all depends on what you're trying to do, so if you want more advice then you'll need to provide more information. HTH has -- Control AppleScriptable applications from Python, Ruby and ObjC: http://appscript.sourceforge.net ___ 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 [EMAIL PROTECTED]
Re: Opening an external file in a external application
On Aug 11, 08, at 2:28 PM, John Love wrote: I have a multiple document Cocoa app where I (try to) open an external file in whatever application the file belongs to -- in my case, an Excel spreadsheet in Excel. The new Cocoa document window shown keeps track of the calculation progress in Excel via a NSProgressIndicator and a NSTextField. So, instead of opening a text file and showing it directly in the NSWindow of MyDocument, I just want to startup Excel by selecting the appropriate file in Cocoa's open dialog. I have 'XLS8' in my "info.plist" file. The Excel spreadsheet opens up and the NSProgressIndicator starts spinning and the appropriate text is placed in the NSTextField. I believe I want to do this opening within my override of - readFromURL. Am I on the right track here? John Love Found the answer -- I do need to override -readFromURL in the following manner: - (BOOL) readFromURL:(NSURL*)absoluteURL ofType:(NSString*)typeName error:(NSError**)outError { NSWorkspace *workSpace; BOOL success; workSpace = [NSWorkspace sharedWorkspace]; success = [workSpace openURL:absoluteURL]; if (success) { // do stuff here } else { // other things here } } I still need to figure out if it is possible for Excel to communicate back to my app via some sort of NSNotification. I don't have much hope of that .. so what I probably need to focus on is how to display the Excel spreadsheet in my document window. Any ideas will definitely be very appreciated. John Love P.S. -- sorry about the initial double post ___ 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 [EMAIL PROTECTED]
Opening an external file in a external application
I have a multiple document Cocoa app where I (try to) open an external file in whatever application the file belongs to -- in my case, an Excel spreadsheet in Excel. The new Cocoa document window shown keeps track of the calculation progress in Excel via a NSProgressIndicator and a NSTextField. So, instead of opening a text file and showing it directly in the NSWindow of MyDocument, I just want to startup Excel by selecting the appropriate file in Cocoa's open dialog. I have 'XLS8' in my "info.plist" file. The Excel spreadsheet opens up and the NSProgressIndicator starts spinning and the appropriate text is placed in the NSTextField. I believe I want to do this opening within my override of - readFromURL. Am I on the right track here? John Love ___ 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 [EMAIL PROTECTED]
Opening an external file in a external application
I have a multiple document Cocoa app where I (try to) open an external file in whatever application the file belongs to -- in my case, an Excel spreadsheet in Excel. The new Cocoa document window shown keeps track of the calculation progress in Excel via a NSProgressIndicator and a NSTextField. So, instead of opening a text file and showing it directly in the NSWindow of MyDocument, I just want to startup Excel by selecting the appropriate file in Cocoa's open dialog. I have 'XLS8' in my "info.plist" file. The Excel spreadsheet opens up and the NSProgressIndicator starts spinning and the appropriate text is placed in the NSTextField. I believe I want to do this opening within my override of - readFromURL. Am I on the right track here? John Love ___ 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 [EMAIL PROTECTED]