hyperlink menu item in xcode?

Discussion in 'Mac Programming' started by BollywooD, Aug 5, 2007.

  1. macrumors 6502

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
    #1
    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:(
     
  2. macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #2
    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];
    }
     
  3. thread starter macrumors 6502

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
    #3
  4. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    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]
    
     
  5. thread starter macrumors 6502

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
    #5
    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

     
  6. macrumors regular

    GothicChess.Com

    Joined:
    Apr 6, 2007
    Location:
    Philadelphia, PA
    #6
    And is there a Carbon equivalent for this?

    :)
     
  7. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #7
    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);
     

Share This Page