Programmatically open Mac App Store
Asked Answered
F

4

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?

Fireguard answered 13/4, 2011 at 23:5 Comment(0)
A
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/"]];
Afterdamp answered 13/4, 2011 at 23:8 Comment(6)
Indeed it is. :) It's called a URI scheme, btw. ;) You can even register your own for your app Particularly handy for incorporating bookmarklet support. ;)Afterdamp
Regexident, This method do not work under sandbox, you will get "deny file-write-data /Applications/App Store.app"Tsui
@DavidL: yes, that warning is during debug only now under Xcode 4.5.2Tsui
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).Breadboard
Is there a way to open a specific developer page listing all of the developers apps using this approach?Lahey
I'm for almost 4 years searching answers for this question and still could not find a code that works.Daystar
A
7

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

Anking answered 8/11, 2012 at 17:3 Comment(0)
E
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.

Exponent answered 13/4, 2011 at 23:8 Comment(0)
Y
0

How about:

[[NSWorkspace sharedWorkspace] launchApplication:@"/Applications/App Store.app"]
Yarrow answered 13/4, 2011 at 23:9 Comment(2)
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.Afterdamp
Though if you want to open a specific app in the App store, then Regexident's answer is better.Yarrow

© 2022 - 2024 — McMap. All rights reserved.