PDA

View Full Version : hyperlink menu item in xcode?




BollywooD
Aug 5, 2007, 08:32 AM
I have built a small applescript studio application, and would like to add a link to my homepage in the the file menu. I have absolutely no idea where to start, and actually thought it would be relatively simple...

I made an applescript script and tried to attach the menu item to it, as you would attach a button event to a script, but that doesnt work.... the menu stays greyed out when i test it.

can anyone point me in the right direction, Ive scoured Google but cant find anything....

cheers in advance:(



Eraserhead
Aug 5, 2007, 09:07 AM
In Objective-C in my program D&D Manager (www.erasersoft.com/) I use this code:

-(IBAction)loadWebsite:(id)sender{
NSURL *url=[NSURL URLWithString:@"http://www.erasersoft.com/main2/Download.html"];
[[NSWorkspace sharedWorkspace] openURL:url];
}

BollywooD
Aug 5, 2007, 08:07 PM
thanks, but I have no experience with Objective-C - how exactly would i implement that?

ive tried following the tutorials here:
http://camelbones.sourceforge.net/documentation/getstarted/menuevents.html

and building that code as a an Objective-C class

(I have no idea really...)

kainjow
Aug 5, 2007, 09:48 PM
In your MainMenu.nib, create your menu item object. Then select it, and choose the AppleScript option in the Inspector window. Give it a name (I chose goToWebsite), and check the option "choose menu item" under Menu. Under Script at the bottom, check your script name.

81508

Go back to Xcode and it will give you code like this:

on choose menu item theObject
(*Add your script here.*)
end choose menu item

Change this to:

on choose menu item theObject
if name of theObject is "goToWebsite" then
open location "http://www.apple.com"
end if
end choose menu item

BollywooD
Aug 5, 2007, 10:34 PM
thankyou, thankyou, thankyou!!!!!

I had hoped it would be this easy, I wasnt really that keen on having to learn some Objective-C just to add a hyperlink.:D

In your MainMenu.nib, create your menu item object. Then select it, and choose the AppleScript option in the Inspector window. Give it a name (I chose goToWebsite), and check the option "choose menu item" under Menu. Under Script at the bottom, check your script name.

81508

Go back to Xcode and it will give you code like this:

on choose menu item theObject
(*Add your script here.*)
end choose menu item

Change this to:

on choose menu item theObject
if name of theObject is "goToWebsite" then
open location "http://www.apple.com"
end if
end choose menu item

GothicChess.Com
Aug 6, 2007, 08:36 AM
In Objective-C in my program D&D Manager (www.erasersoft.com/) I use this code:

-(IBAction)loadWebsite:(id)sender{
NSURL *url=[NSURL URLWithString:@"http://www.erasersoft.com/main2/Download.html"];
[[NSWorkspace sharedWorkspace] openURL:url];
}

And is there a Carbon equivalent for this?

:)

kainjow
Aug 6, 2007, 08:51 AM
And is there a Carbon equivalent for this

Use LaunchServices (code untested):

static const char myURL[] = "http://www.apple.com";
CFURLRef url = CFURLCreateWithBytes(NULL, (const UInt8 *)myURL, sizeof(myURL), kCFStringEncodingASCII, NULL);
LSOpenCFURLRef(url, NULL);
CFRelease(url);