【问题标题】:URL scheme Mac App Store SearchURL 方案 Mac App Store 搜索
【发布时间】:2013-11-05 14:48:02
【问题描述】:

我想用 URL 方案打开 Mac App Store

十月之前我使用了下面的链接

macappstore://ax.search.itunes.apple.com/WebObjects/MZSearch.woa/wa/search?q=

后跟一个搜索词,如things

知道新的 URL 方案 在 OS X 10.9 Mavericks 上的样子吗?

【问题讨论】:

  • 这不是小牛队相关的问题。 Mac App Store 的 API 搜索在通过 Web 访问时也返回正好 0 个结果:itunes.apple.com/… 尽管官方文档(最后更新于 2012 年 10 月)仍然说它是正确的。不过仍然适用于 iOS 的东西。我猜苹果内部正在改变一些东西
  • @kernelpanic 是的,你是对的。山狮确实有同样的问题,只是碰巧与小牛队的发布时间相同。
  • 嗯... - 截至 2013 年 11 月 5 日,我确实发现这是 Mavericks 的问题:在终端中运行以下内容适用于 Mountain Lion,但不适用于 Mavericks: open "macappstore://ax.search.itunes.apple.com/WebObjects/MZSearch.woa/wa/search?q=pixelmator"
  • 似乎又可以工作了。使用完全相同的请求和 URL 方案
  • @kernelpanic:奇怪 - 仍然不适合我。如果你从终端执行open "macappstore://ax.search.itunes.apple.com/WebObjects/MZSearch.woa/wa/search?q=pixelmator",它对你有用吗?这可能是区域性的吗?

标签: app-store osx-mavericks osx-yosemite url-scheme


【解决方案1】:

在 10.11 中,该 URL 似乎发生了细微的变化。新网址如下:

macappstores://search.itunes.apple.com/WebObjects/MZSearch.woa/wa/search?mt=12&ign-mscache=1&q=...

【讨论】:

  • 这对我有用,打开 Mac App Store 应用程序(而不是在 Chrome 中打开)
【解决方案2】:

以下基于AppleScript 的解决方案 只是权宜之计,但在某些情况下可能就足够了;例如,我想从支持 AppleScripts 的 Alfred 2 执行基于命令行的 App Store 搜索。

  • 该脚本适用于 OSX 10.8+(测试到 10.10,这是撰写本文时的最新版本)。
  • 在 10.8 上,它使用 macappstore:// 方法,而在 10.9+ 上,它使用 GUI 脚本 - 通过可访问性 API,而不是通过发送击键,所以它应该相当健壮。
  • 1234563方便)。
  • 要试用该脚本,请将其粘贴到 AppleScript 编辑器中,在顶部放置一个示例调用 - 例如my searchAppStore("dash"),然后运行它。

    # Performs an App Store search via the App Store.app.
    # Example:
    #   my searchAppStore("dash")
    # Works on OS X 10.8+:
    # - 10.8: Uses the macappstore:// URL scheme.
    # - 10.9+: Sadly, GUI scripting (i.e., simulated user input) must be used,
    #         which requires that access for assistive devices be enabled as *one-time setup*
    #         for the application in whose context this script runs.
    #         While this script attempts to facilitate enabling this feature,
    #         user intervention is - by OS design - required.
    on searchAppStore(searchTerm)
    
        if my isPreMavericks() then # assumes: OS X 10.8
    
            # We can use the macappstore:// URL scheme to submit a search.
            tell application "System Events" to open location "macappstore://ax.search.itunes.apple.com/WebObjects/MZSearch.woa/wa/search?q=" & searchTerm
            return
    
        else # OS X 10.9+: alas, we must use GUI scripting.
    
            # First, ensure that access for assistive devices is enabled - 
            # otherwise, GUI scripting won't work.
            my ensureAssistiveAccess()
    
            # Activate (and launch, if necessary) the App Store app.
            tell application "App Store" to activate
    
            # Use GUI scripting to simulate an interactive search.
            tell application "System Events"
                tell application process "App Store"
                    # !! CAVEAT: The spelling of the toolbar UI element changed from 'tool bar' (10.8)
                    # !!         to 'toolbar' (10.9) - if you compile this script on 10.9, you'll end
                    # !!         up with 'toolbar', which will break when PASTED into a 10.8 AppleScript
                    # !!         window. If you're on 10.8 and get an error, change 'toolbar' to 'tool bar'.
                    set searchTextField to get text field 1 of group 7 of tool bar 1 of front window
                    set searchSubmitButton to get button 1 of searchTextField
                    set ok to false
                    repeat with i from 1 to 20 # Timeout is iteration count * delay period below.
                        set value of attribute "AXValue" of searchTextField to searchTerm
                        # !! Sadly, when App Store.app was just launched by this script, attempts to
                        # !! assign to the search field initially fail silently, until some time
                        # !! after startup. We simply keep trying for a while until we succeed.
                        if (value of attribute "AXValue" of searchTextField) = searchTerm then
                            # Click button to submit search.
                            # [If you run this on 10.8]
                            # !! On OS X 10.8, if this script just launched App Store.app,
                            # !! `tell application "App Store" to activate` didn't actually
                            # !! *activate* the app (it just launched it).
                            # !! Hence, we simply activate again here - BEFORE we
                            # !! submit the search - otherwise, it may not work.
                            tell application "App Store" to activate
                            click searchSubmitButton
                            # We're done.
                            return
                        end if
                        delay 0.3
                    end repeat
    
                    # Getting here means that submitting did not succeed within the timeout period.
                    # Raise an error.
                    error "Failed to submit search search term to the App Store application."
    
                end tell
            end tell
    
        end if
    end searchAppStore
    
    
    # Tries to ensure that access for assistive devices is turned on so as to enable GUI scripting.
    # - Up to 10.8.x, access can be turned on programmatically, on demand - via an admin authorization prompt.
    # - From 10.9, the best we can do is display a GUI prompt, then open System Preferences to the relevant pane, then exit, telling the user to try again after interactively enabling access.
    # Returns:
    #   Only returns if access is already enabled; throws an error otherwise.
    # Example:
    #   my ensureAssistiveAccess() # throws error, if not enabled and couldn't be enabled programmatically (10.9+)
    #   # Alternatively, catch the error: 
    #   try 
    #       my ensureAssistiveAccess()
    #   on error
    #       # Exit quietly, relying on the prompt to have provided sufficient information.
    #       return
    #   end try
    on ensureAssistiveAccess()
        local ok, isPreMavericks, verOs, verMajor, verMinor, btn
        # Determine if access is currently enabled.
        tell application "System Events" to set ok to UI elements enabled
        if not ok then
            # See if we're running 10.8 or below
            set {orgTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {"."}}
            set verOs to system version of (system info)
            set verMajor to first text item of verOs as number
            set verMinor to second text item of verOs as number
            set AppleScript's text item delimiters to orgTIDs
            set isPreMavericks to verMajor ≤ 10 and verMinor < 9
            if isPreMavericks then # 10.8-: we can try to turn it on ourselves, which will prompt for authorization
                try
                    # Try to turn it on - will prompt for authorization via admin credentials.
                    tell application "System Events"
                        set UI elements enabled to true
                        set ok to UI elements enabled # Check if the user actually provided the authorization.
                    end tell
                end try
            else # 10.9+: we cannot turn it on ourselves, it has to be enabled *interactively*, *per application*.
                # Try a dummy GUI scripting operation - which we know will fail - in the hope that this will
                # get the app at hand registered in System Preferences > Security & Privacy > Privacy > Accessibility.
                # ?? Does this work?
                try
                    tell application "System Events" to windows of process "SystemUIServer"
                end try
                set appName to name of current application
                if appName = "osascript" then set appName to "Terminal" # ?? how can we deal with other apps that invoke `osascript`, such as Alfred?
                set errMsg to "You must turn on ACCESS FOR ASSISTIVE DEVICES for application '" & appName & "' (System Preferences > Security & Privacy > Privacy > Accessibility) first, then retry."
                try
                    display dialog errMsg & linefeed & linefeed & "Press OK to open System Preferences now; unlock, if necessary, then locate the application in the list and check it." with icon caution
                    # We only get here if the user didn't cancel.
                    # Open System Preferences and show the appropriate pane. (This is the best we can do in guiding the user - further guidance would require the very kind of assistive access we're trying to turn on.)
                    tell application "System Preferences"
                        activate
                        tell pane id "com.apple.preference.security"
                            reveal anchor "Privacy_Assistive"
                        end tell
                    end tell
                end try
                # We must return false, as we can't easily and reliably wait for the user to finish the operation.
            end if
        end if
        if not ok then
            if isPreMavericks then # This indicates that the authorization prompt was aborted; for 10.9+, errMsg was set above.         
                set errMsg to "You must turn on ACCESS FOR ASSISTIVE DEVICES first, via System Preferences > Accessibility > Enable access for assistive devices"
            end if
            error errMsg
        else
            return true
        end if
    end ensureAssistiveAccess
    
    # Indicates if the OS version predates Mavericks (10.9).
    # Example: my isPreMavericks() # -> true on 10.8.x and below
    on isPreMavericks()
        local verOs, verMajor, verMinor
        set {orgTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {"."}}
        set verOs to system version of (system info)
        set verMajor to first text item of verOs as number
        set verMinor to second text item of verOs as number
        set AppleScript's text item delimiters to orgTIDs
        return verMajor ≤ 10 and verMinor < 9
    end isPreMavericks
    

【讨论】:

  • 哇!完美的答案。我将它复制到Alfred 2 工作流程中,它运行良好。您甚至考虑过使用旧版 Mavericks 系统的速度提升。非常感谢。
  • 我的荣幸;我很高兴听到它对你有用,@ViktorLexington。感谢您提供赏金。
【解决方案3】:

只需将“&mt=12”添加到现有 iTunes Store 链接即可。 这会将查询重定向到 Mac AppStore 应用程序而不是 iTunes。

MAS 中的搜索查询示例:

https://search.itunes.apple.com/WebObjects/MZSearch.woa/wa/search?q=equinux&mt=12

【讨论】:

  • 这是一个不错的选择,但缺点是途中会经过Safari。
猜你喜欢
  • 2016-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-17
  • 2021-06-30
  • 2011-08-05
  • 2011-06-05
相关资源
最近更新 更多