[futurebasic] Open URL with Launch Services Demo

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : June 2004 : Group Archive : Group : All Groups

From: Ken Shmidheiser <kshmidheiser@...>
Date: Wed, 23 Jun 2004 02:49:05 -0400
In many of my recent internet access demos, I 
have used FB^3's convenient Open "Unix" function 
to invoke Unix commands. I am comfortable in the 
Terminal and with Unix and find it convenient and 
the code tight and easy to understand.

That said, Apple's new Toolbox way to launch URLs 
is no longer InternetConfig, but Launch Services. 
(While internetConfig may be available, it 
actually wraps around Launch Services). The suite 
of Launch Services functions can handle quite a 
variety of things. The following demo shows how 
Launch Services can be used to launch a variety 
of URLs.

The nice thing about Launch Services is that much 
of the detail work is handled by the function. 
For instance, FTP sites are opened directly in 
the Finder, bypassing an FTP client, which can be 
extremely convenient.

A mailto URL can be configured like a standard 
web link with the exception that certain 
characters, such as spaces, must be escaped with 
standard HTML escape codes.

The implementation of other types of URLs is 
straight forward. with Launch Services doing the 
bulk of the work. Some samples are included.

Perhaps you will find this technique useful.

Ken


/*

Open URL with Launch Services Demo

   This demo uses OS X Launch Services functions
   to open various kinds of URLs:

   http   -- Will open in default browser
   mailto -- Will open in default email client
   ftp    -- Opens directly in Finder (kinda neat!)


   Ken Shmidheiser
   Somerset, KY

   June 23, 2004

*/

toolbox fn CFURLCreateWithString ( CFAllocatorRef allocator,¬
                                       CFStringRef URLString,¬
                               CFURLRef baseURL ) = CFURLRef

toolbox fn LSOpenCFURLRef ( CFURLRef inURL,¬
                   CFURLRef *outLaunchedURL ) = OSStatus


local fn LSLaunchURL( urlStr as str255 )
'~'1
dim as OSStatus  stat
dim as CFURLRef  urlRef

urlRef = fn CFURLCreateWithString( _nil, fn CFSTR( urlStr ), _nil )
long if ( urlRef )
stat = fn LSOpenCFURLRef( urlRef, #_nil )
CFRelease( urlRef )
end if

end fn = stat

// fn LSLaunchURL( "http://www.apple.com/macosx" )

fn LSLaunchURL( "mailto:joe@...?subject=Test%20Subject¬
?cc=ed@...?body=Hello%20everyone" )

// fn LSLaunchURL( "ftp://userName:password@..." )

do
handleevents
until gFBQuit