Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

BollywooD

macrumors 6502
Original poster
Apr 27, 2005
371
46
Hamburg
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

macrumors G4
Nov 3, 2005
10,434
12,250
UK
In Objective-C in my program D&D Manager I use this code:

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

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
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.

View attachment 81508

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

Code:
[b][color=blue]on[/color][/b] [color=blue]choose menu item[/color] [color=green]theObject[/color]
     (*[i][color=olive]Add your script here.[/color][/i]*)
[b][color=blue]end[/color][/b] [color=blue]choose menu item[/color]

Change this to:

Code:
[b][color=blue]on[/color][/b] [color=blue]choose menu item[/color] [color=green]theObject[/color]
     [b][color=blue]if[/color][/b] [color=blue]name[/color] [b][color=blue]of[/color][/b] [color=green]theObject[/color] [b][color=blue]is[/color][/b] "goToWebsite" [b][color=blue]then[/color][/b]
          [color=blue]open location[/color] "http://www.apple.com"
     [b][color=blue]end[/color][/b] [b][color=blue]if[/color][/b]
[b][color=blue]end[/color][/b] [color=blue]choose menu item[/color]
 

BollywooD

macrumors 6502
Original poster
Apr 27, 2005
371
46
Hamburg
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.

View attachment 81508

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

Code:
[b][color=blue]on[/color][/b] [color=blue]choose menu item[/color] [color=green]theObject[/color]
     (*[i][color=olive]Add your script here.[/color][/i]*)
[b][color=blue]end[/color][/b] [color=blue]choose menu item[/color]

Change this to:

Code:
[b][color=blue]on[/color][/b] [color=blue]choose menu item[/color] [color=green]theObject[/color]
     [b][color=blue]if[/color][/b] [color=blue]name[/color] [b][color=blue]of[/color][/b] [color=green]theObject[/color] [b][color=blue]is[/color][/b] "goToWebsite" [b][color=blue]then[/color][/b]
          [color=blue]open location[/color] "http://www.apple.com"
     [b][color=blue]end[/color][/b] [b][color=blue]if[/color][/b]
[b][color=blue]end[/color][/b] [color=blue]choose menu item[/color]
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
And is there a Carbon equivalent for this

Use LaunchServices (code untested):

Code:
static const char myURL[] = "http://www.apple.com";
CFURLRef url = CFURLCreateWithBytes(NULL, (const UInt8 *)myURL, sizeof(myURL), kCFStringEncodingASCII,  NULL);
LSOpenCFURLRef(url, NULL);
CFRelease(url);
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.