Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 30, 2008, 04:32 AM   #1
printf
macrumors regular
 
Join Date: Aug 2008
launch html file from web browser in carbon

the title says it all. i'm trying to launch html-based help files in the same directory as my app.

i've tried both LSOpenCFURLRef, as well as LSOpenFSRef, but can only get them to work with www urls but NOT local files like "file:///Developer/help.html". all i get is an OSStatus of -43, which doesn't seem to be in the range of the documented Launch Services result codes.

anyone ever get this to work?
printf is offline   0 Reply With Quote
Old Nov 30, 2008, 05:38 AM   #2
hhas
macrumors member
 
Join Date: Oct 2007
Quote:
Originally Posted by printf View Post
the title says it all. i'm trying to launch html-based help files in the same directory as my app.
Assuming these help files belong to your application, the simplest solution would be to use the standard Carbon/Cocoa help system:

http://developer.apple.com/documenta...elp/index.html
__________________
Learn AppleScript, 3rd edition, Sanderson & Rosenthal:
http://apress.com/book/view/9781430223610
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net
hhas is offline   0 Reply With Quote
Old Nov 30, 2008, 06:17 AM   #3
printf
Thread Starter
macrumors regular
 
Join Date: Aug 2008
hhas, thanks for your response and that link.

i'd love to adopt that system, and probably will somehow in the future, but for the sake of time, and because this is the same system used in my win32 app, i need to just pop open the html files using the aforementioned technique.

any idea how?
printf is offline   0 Reply With Quote
Old Nov 30, 2008, 11:51 AM   #4
hhas
macrumors member
 
Join Date: Oct 2007
Quote:
Originally Posted by printf View Post
i need to just pop open the html files using the aforementioned technique.
-43 = file not found. Probably your URL is wrong. Post the relevant code if you want specifics.
__________________
Learn AppleScript, 3rd edition, Sanderson & Rosenthal:
http://apress.com/book/view/9781430223610
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net
hhas is offline   0 Reply With Quote
Old Nov 30, 2008, 12:15 PM   #5
Sayer
macrumors 6502a
 
Sayer's Avatar
 
Join Date: Jan 2002
Location: Austin, TX
You need to get a CFURL reference to the html file to open, most likely in the app bundle. So first you get a reference to the main app's bundle, which you can then use to get the embedded HTML file.

so do:

Code:
CFBundle bundle = CFGetMainBundle();
CFURL  = CFBundleCopyResourceURL( bundle, "Help", "html", "HelpContentFolder" );
So "Help" is the file name minus extension, "html" is the file type extension (hurray for Unix/Windows!) and "HelpContentFolder" is the name of the folder in the Resources folder inside the app bundle that contains the Help files.

App Bundle > Contents > Resources > HelpContentFolder

Then its just a matter of: Pass that CFURL to LSOpenCFURLRef.
__________________
Obama is a true statesman whose experience as a state senator, half-term US Senator & guest lecturer in a Constitutional Law class has fully prepared him to take control of our nuclear arsenal.-Me

Last edited by Sayer; Nov 30, 2008 at 12:20 PM.
Sayer is offline   0 Reply With Quote
Old Nov 30, 2008, 04:16 PM   #6
printf
Thread Starter
macrumors regular
 
Join Date: Aug 2008
Quote:
Originally Posted by hhas View Post
-43 = file not found. Probably your URL is wrong. Post the relevant code if you want specifics.
here's both my attempts at this. i hard-coded the path in place of CFBundleCopyBundleURL(CFBundleGetMainBundle()), where my help files are stored just to eliminate any further points of failure. and i can assure you, that html file is in fact at that location.

Code:
//attempt 1
CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR("file:///Developer/Projects/help.html"), kCFURLPOSIXPathStyle, false);
OSStatus result = LSOpenCFURLRef(url,NULL);

//attempt 2
FSRef ref = {0};
Boolean isDir = false;			
OSStatus result = FSPathMakeRef((UInt8 *)"file:///Developer/Projects/help.html", &ref, &isDir);			
LSOpenFSRef(&ref,NULL);
and sayer, if i'm understanding you correctly that would require the help files to be 'inside' the app. i'd like the help to be external from the app so updates don't require a full download of the main app, and so the user can get to help without the app being loaded.
printf is offline   0 Reply With Quote
Old Nov 30, 2008, 04:33 PM   #7
kainjow
Demi-God (Moderator emeritus)
 
kainjow's Avatar
 
Join Date: Jun 2000
In your examples you are passing the absolute string of a file URL instead of the absolute path.
kainjow is offline   0 Reply With Quote
Old Nov 30, 2008, 04:38 PM   #8
printf
Thread Starter
macrumors regular
 
Join Date: Aug 2008
Quote:
Originally Posted by kainjow View Post
In your examples you are passing the absolute string of a file URL instead of the absolute path.
haha kainjow, i had JUST figured that out and came back to post my result!!! haha, thanks! (and i think you meant relative in the second part)

note to self: read EVERY line of the api documentation!
printf is offline   0 Reply With Quote
Old Nov 30, 2008, 04:44 PM   #9
printf
Thread Starter
macrumors regular
 
Join Date: Aug 2008
for posterity:

Code:
CFURLRef fURL = CFURLCreateWithFileSystemPath(NULL, CFSTR("Help/help.html"), kCFURLPOSIXPathStyle, false); //Help resides in folder relative to app
LSOpenCFURLRef(fURL, NULL);
printf is offline   0 Reply With Quote
Old Nov 30, 2008, 04:49 PM   #10
kainjow
Demi-God (Moderator emeritus)
 
kainjow's Avatar
 
Join Date: Jun 2000
Hm I could be wrong, but I don't think that code will work all the time. Did you test it by running your app outside of Xcode (e.g. via the Finder)? Xcode sets the current working directory usually to the Debug/Release directory, but the Finder doesn't.
kainjow is offline   0 Reply With Quote
Old Nov 30, 2008, 04:57 PM   #11
printf
Thread Starter
macrumors regular
 
Join Date: Aug 2008
Quote:
Originally Posted by kainjow View Post
Hm I could be wrong, but I don't think that code will work all the time. Did you test it by running your app outside of Xcode (e.g. via the Finder)? Xcode sets the current working directory usually to the Debug/Release directory, but the Finder doesn't.
awww crap, you're right - it doesn't work when launched from finder! how do i get around that then?
printf is offline   0 Reply With Quote
Old Nov 30, 2008, 05:15 PM   #12
kainjow
Demi-God (Moderator emeritus)
 
kainjow's Avatar
 
Join Date: Jun 2000
Well if the Help folder is in the same folder as your .app you can use CFBundleCopyBundleURL() and manipulate it from there (as a URL, or convert to C-string, etc). But since we're dealing with a Mac app, the Help folder *should* be located inside the .app's Resources folder, and if that's the case you can use Sayer's recommendation of CFBundleCopyResourceURL.
kainjow is offline   0 Reply With Quote
Old Nov 30, 2008, 06:11 PM   #13
printf
Thread Starter
macrumors regular
 
Join Date: Aug 2008
kainjow, does this theory apply to dylib files as well? i just noticed dlopen is failing if i pass in a relative path and run my app from finder - but it works when i run it in xcode..

if so, that would seem contradictory to the point of a 'dynamically' linked lib, methinks
printf is offline   0 Reply With Quote
Old Nov 30, 2008, 07:24 PM   #14
printf
Thread Starter
macrumors regular
 
Join Date: Aug 2008
i was able to fix the dlopen issue using CFBundleCopyBundleURL(CFBundleGetMainBundle()), however my question still stands.

is the mac standard to package dylib's with the .app's bundle? if this is the case, i would greatly appreciate a link to documentation on this, so i can follow these best practices!
printf is offline   0 Reply With Quote
Old Nov 30, 2008, 07:27 PM   #15
kainjow
Demi-God (Moderator emeritus)
 
kainjow's Avatar
 
Join Date: Jun 2000
Yes, you can link to a dylib inside your application bundle. You have to copy it to a certain folder (probably Contents/Frameworks), and then write a run script to use install_name_tool to set the path to relative based on the directory. I used to do this with a project but I don't have the script anymore.
kainjow is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Question regarding WebView component in Mac Web Browser gwelmarten Mac Programming 4 Feb 21, 2011 05:05 PM
Question regarding WebView component in Mac Web Browser gwelmarten Mac Programming 0 Feb 15, 2011 11:59 AM
weird problem on web browser for Macbook Pro jianadmu Mac Applications and Mac App Store 0 Feb 10, 2011 05:07 AM
Looking for a piece of web software for creating HTML links from Webloc Browser Pages macsrules Web Design and Development 2 Mar 17, 2009 10:04 PM
Launching a mp3 from a browser into iTunes mikemodena Mac Applications and Mac App Store 3 Aug 10, 2005 07:43 PM


All times are GMT -5. The time now is 08:44 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC