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

furycd001

macrumors member
Original poster
Mar 9, 2011
65
0
Belfast
HI everyone

How would I go about linking a button or an image to a url in xcode / interface builder :?

Basically what I would like to do is have a button or image within an app on my mac desktop, that whenever clicked it will take me to a specified hardcoded url. All the tutorials I have found online refer to creating IOS based apps. Any help would be appreciated & sorry is this is a dead silly question...
 

furycd001

macrumors member
Original poster
Mar 9, 2011
65
0
Belfast
What have you tried so far that didn't work?

I haven't really tried anything because I am unsure of what to connect the button to. I have though tried following some tutorials though they were iphone based, so I new they wouldn't work.

Someone on a programming irc channel told me to try the following...
Try creating an action handler in the script object, then connecting the button to the newly created handler. The code in the handler will check to see what button was pressed, then it will take the appropriate action.
If this would work how would I go about creating an action handler ??

Sorry but I am relatively new to programming & still learning. Your help will be much appreciated.
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,558
6,058
iOS and OS X are pretty darn similar... I would suspect that you can follow an iOS tutorial for this task to the t for an OS X app and end up with the same app (but for OS X, of course.)

Edit: Well, the code for opening the URL might change... Try just hooking up a button to an IBAction that NSLogs the URL first. Then you can look into opening a URL on OS X.
 

xStep

macrumors 68020
Jan 28, 2003
2,031
143
Less lost in L.A.
Basically what I would like to do is have a button or image within an app on my mac desktop, that whenever clicked it will take me to a specified hardcoded url.

I'm confused. Which is it? You want an icon on your desktop that you can double click to go to a specific URL, or you want a button within an app that takes you to a URL? Those are two different things.

If the first, simply drag the URL from Safari to the desktop. Automator maybe another simple option for this tactic.

If the second, look at using the openURL: method of the NSWorkspace.
Code:
   NSURL * mtDotCom = [NSURL URLWithString: @"http://www.morphedthoughts.com"];
   [[NSWorkspace sharedWorkspace] openURL: mtDotCom];
 

furycd001

macrumors member
Original poster
Mar 9, 2011
65
0
Belfast
Thanks for the replies everyone.

No I don't want an icon on my desktop, I was just either going to use a button or an image for the link in my app (i've decided on button). Thank you for the snippet of code, I will give that a whirl & see what happens. I will also try IBAction too...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.