28

I am trying to programmatically open the Mac App Store in a custom Mac App. I started with the link below.

http://itunes.apple.com/us/app/angry-birds/id403961173?mt=12

I tried the following code, however it opens the browser rather than the Mac App Store.

[[NSWorkspace sharedWorkspace] openURL:
 [NSURL URLWithString:@"http://itunes.apple.com/us/app/angry-birds/id403961173?mt=12"]];

Any suggestions on how I can do this?

David
  • 14,205
  • 20
  • 97
  • 144

4 Answers4

69

URLs of this pattern open up the Mac App Store:

macappstore://itunes.apple.com/app/id403961173?mt=12

So in your case:

[[NSWorkspace sharedWorkspace] openURL:
 [NSURL URLWithString:@"macappstore://itunes.apple.com/app/id403961173?mt=12"]];

will open the MAS and load the product page associated with id #403961173 (here: Angry Birds).

To just load the MAS, with no particular product page use this URL:

[[NSWorkspace sharedWorkspace] openURL:
 [NSURL URLWithString:@"macappstore://itunes.apple.com/"]];
Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
Regexident
  • 29,441
  • 10
  • 93
  • 100
  • 1
    Indeed it is. :) It's called a [URI scheme](http://en.wikipedia.org/wiki/URI_scheme), btw. ;) You can even [register your own for your app](http://stackoverflow.com/questions/5463998/how-to-programmatically-register-a-custom-url-scheme) Particularly handy for incorporating bookmarklet support. ;) – Regexident Apr 13 '11 at 23:20
  • Regexident, This method do not work under sandbox, you will get "deny file-write-data /Applications/App Store.app" – Jiulong Zhao Jun 28 '12 at 22:18
  • @DavidL: yes, that warning is during debug only now under Xcode 4.5.2 – Jiulong Zhao Nov 09 '12 at 20:27
  • Cool; for merely launching/activating the MAS it seems that `macappstore://` or even just `macappstore:` is sufficient (as of at least OS X 10.8.3). – mklement0 Apr 17 '13 at 15:59
  • Is there a way to open a specific developer page listing all of the developers apps using this approach? – inexcitus Sep 04 '18 at 11:23
  • I'm for almost 4 years searching answers for this question and still could not find a code that works. – Cezar Wagenheimer Dec 19 '22 at 18:07
7

If you just want to show the updates page you can use this URL: macappstore://showUpdatesPage

Yoav
  • 5,962
  • 5
  • 39
  • 61
0

open the webpage in a UIWebView. the webview will then open itunes, or at least ask to open itunes.

that may be iphone specific. but whatever the WebView is for mac.

The Lazy Coder
  • 11,560
  • 4
  • 51
  • 69
0

How about:

[[NSWorkspace sharedWorkspace] launchApplication:@"/Applications/App Store.app"]
Marc Abramowitz
  • 3,447
  • 3
  • 24
  • 30
  • 3
    This will only open the MAS. But what it won't allow you is to choose a product page to open it with. That's where the URL scheme comes into play. – Regexident Apr 13 '11 at 23:12
  • 1
    Though if you want to open a specific app in the App store, then [Regexident's answer](http://stackoverflow.com/questions/5656746/programmatically-open-mac-app-store/5656762#5656762) is better. – Marc Abramowitz Apr 13 '11 at 23:14