{
    "tailapp": 2,
    "manifest": {
        "format": 2,
        "app_id": "app-ranks",
        "name": "App Ranks",
        "version": 1,
        "schema": "tailapps/v0",
        "exported_at": 1796020330,
        "from": "gallery",
        "connections": [],
        "files": {
            "app.json": "c8aec5910332e9638fd875caed8d9712cdcf00b482f34522c80e37f784ec9a2c"
        },
        "signature": "XVvKTF/NBJSwbBtiQdeKdx/+Z8U0Ygw95UTVZNMZYpHKUWzlvnmkKP7/xwYbkzFbjThhl6lbRTrtdf7fqUPLAA==",
        "key_id": "gallery-1"
    },
    "app": {
        "schema": "tailapps/v0",
        "app": "app-ranks",
        "name": "App Ranks",
        "description": "Where your app sits in the App Store's top 100, country by country, checked every hour on your Mac, with a notification when its best rank moves. The iPhone sees it too.",
        "icon": "chart.line.uptrend.xyaxis",
        "version": 1,
        "permissions": [
            "script:ranks.sh",
            "net:rss.marketingtools.apple.com",
            "notify"
        ],
        "settings": {
            "app_id": {
                "type": "text",
                "label": "App Store id (the digits after id in its link)",
                "required": true,
                "platforms": [
                    "macos"
                ]
            },
            "countries": {
                "type": "text",
                "label": "Countries (two-letter codes)",
                "default": "us,gb,de,fr,jp,au,ca,pl",
                "platforms": [
                    "macos"
                ]
            },
            "chart": {
                "type": "select",
                "label": "Chart",
                "options": [
                    "top-free",
                    "top-paid"
                ],
                "default": "top-free",
                "platforms": [
                    "macos"
                ]
            }
        },
        "scripts": {
            "ranks.sh": "#!/bin/sh\n# Your app's place in Apple's public top-100 charts, one country at a time, as JSON:\n# { \"countries\": [{ \"country\": \"gb\", \"rank\": 12, \"name\": \"\u2026\" }, \u2026], \"best\": 12, \"best_country\": \"gb\", \"charted\": 3, \"name\": \"\u2026\" }\n# $1 = the App Store id (the digits after \"id\" in the app's link), $2 = countries like \"us,gb,pl\", $3 = top-free or top-paid.\nid=\"$1\"\nchart=\"$3\"\ncase \"$id\" in ''|*[!0-9]*) echo \"The app id is the digits after \\\"id\\\" in its App Store link, like 1234567890\" >&2; exit 1 ;; esac\ncase \"$chart\" in top-free|top-paid) ;; *) chart=top-free ;; esac\nout=\"\"\nfetched=0\nfor c in $(printf '%s' \"$2\" | tr ',;' '  '); do\n  c=$(printf '%s' \"$c\" | tr 'A-Z' 'a-z' | tr -cd 'a-z')\n  [ ${#c} -eq 2 ] || continue\n  if feed=$(curl -fsS --max-time 12 \"https://rss.marketingtools.apple.com/api/v2/$c/apps/$chart/100/apps.json\" 2>/dev/null); then\n    fetched=$((fetched + 1))\n  else\n    feed='{}'\n  fi\n  row=$(printf '%s' \"$feed\" | jq -c --arg id \"$id\" --arg c \"$c\" '\n    (.feed.results // []) as $r\n    | { country: $c,\n        rank: ($r | map(.id) | index($id) | if . == null then null else . + 1 end),\n        name: ($r | map(select(.id == $id)) | .[0].name) }' 2>/dev/null) || row=\"{\\\"country\\\":\\\"$c\\\",\\\"rank\\\":null,\\\"name\\\":null}\"\n  out=\"$out${out:+,}$row\"\ndone\n# No chart at all (offline, or Apple's feed is down) is an error, not \"out of the top 100\" everywhere.\n[ \"$fetched\" -gt 0 ] || { echo \"Couldn't reach the App Store charts\" >&2; exit 1; }\nprintf '[%s]' \"$out\" | jq -c '\n  (map(select(.rank != null))) as $in\n  | { countries: .,\n      best: ($in | map(.rank) | min),\n      best_country: (if ($in | length) > 0 then ($in | min_by(.rank) | .country) else null end),\n      charted: ($in | length),\n      name: ($in | map(.name) | .[0]) }'\n"
        },
        "state": {
            "latest": {
                "type": "object",
                "default": [],
                "sync": true
            },
            "history": {
                "type": "list",
                "default": [],
                "sync": true
            }
        },
        "sources": {
            "ranks": {
                "script": "ranks.sh",
                "args": [
                    "$settings.app_id",
                    "$settings.countries",
                    "$settings.chart"
                ],
                "every": 3600,
                "timeout": 120,
                "platforms": [
                    "macos"
                ],
                "on_change": {
                    "action": "checked",
                    "watch": "{$ranks.best} {$ranks.charted}"
                }
            }
        },
        "actions": {
            "checked": {
                "runs_on": [
                    "macos"
                ],
                "steps": [
                    {
                        "if": "$latest.at",
                        "then": [
                            {
                                "if": "$ranks.best",
                                "then": [
                                    {
                                        "notify": {
                                            "title": "{$ranks.name | default:'Your app'} is #{$ranks.best}",
                                            "body": "Best place now, in {$ranks.best_country | upper} ({$ranks.charted} of your countries)"
                                        }
                                    }
                                ],
                                "else": [
                                    {
                                        "notify": {
                                            "title": "Out of the top 100",
                                            "body": "Not in the top 100 in any of your countries"
                                        }
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        "set": {
                            "latest": {
                                "best": "$ranks.best",
                                "best_country": "$ranks.best_country",
                                "charted": "$ranks.charted",
                                "name": "$ranks.name",
                                "countries": "$ranks.countries",
                                "at": "$now"
                            }
                        }
                    },
                    {
                        "push": {
                            "history": {
                                "at": "$now",
                                "best": "$ranks.best"
                            }
                        },
                        "at": "end",
                        "max": 72
                    }
                ]
            },
            "check_now": {
                "runs_on": [
                    "macos"
                ],
                "steps": [
                    {
                        "refresh": "ranks"
                    }
                ]
            },
            "clear_history": {
                "confirm": "Clear the rank history on all your devices?",
                "steps": [
                    {
                        "set": {
                            "history": []
                        }
                    }
                ]
            }
        },
        "cards": [
            {
                "id": "main",
                "layout": {
                    "column": [
                        {
                            "row": [
                                {
                                    "stat": "$latest.best | map:{null:'\u2014'}",
                                    "label": "Best rank",
                                    "size": "xl"
                                },
                                {
                                    "spacer": true
                                },
                                {
                                    "stat": "$latest.charted | default:'0'",
                                    "label": "Countries in the top 100"
                                }
                            ],
                            "align": "start"
                        },
                        {
                            "text": "{$latest.name | default:'Your app'} \u00b7 best in {$latest.best_country | upper}",
                            "size": "s",
                            "emphasis": "subtle",
                            "when": "$latest.best"
                        },
                        {
                            "chart": "$history | pluck:'best'",
                            "kind": "line",
                            "height": "s",
                            "hue": "blue",
                            "when": "$history | count"
                        },
                        {
                            "column": [
                                {
                                    "list": "$latest.countries",
                                    "empty": "No check yet. Set your app's id in Settings on your Mac.",
                                    "item": {
                                        "cell": "$item.country | upper",
                                        "leading": "$item.country | flag",
                                        "subtitle": "$item.rank | map:{null:'Not in the top 100', else:'In the top 100'}",
                                        "trailing": {
                                            "badge": "#{$item.rank}",
                                            "tone": "$item.rank | tone:{good:'<=10', warn:'<=50', else:'neutral'}",
                                            "when": "$item.rank"
                                        }
                                    }
                                }
                            ],
                            "style": "inset"
                        }
                    ],
                    "gap": "m"
                },
                "footer": {
                    "row": [
                        {
                            "text": "Checked {$latest.at | ago}",
                            "size": "s",
                            "emphasis": "subtle",
                            "when": "$latest.at"
                        },
                        {
                            "spacer": true
                        },
                        {
                            "button": "Check now",
                            "on": "check_now",
                            "style": "plain",
                            "disabled": "$running.check_now",
                            "platforms": [
                                "macos"
                            ]
                        }
                    ],
                    "align": "center"
                }
            }
        ],
        "views": {
            "menubar": {
                "icon": "chart.line.uptrend.xyaxis",
                "label": "Rank {$latest.best | map:{null:'\u2014'}}",
                "label_tone": "$latest.best | tone:{good:'<=10', else:'neutral'}",
                "card": "main",
                "in_menu": "row"
            },
            "floating": {
                "card": "main",
                "width": "default"
            }
        },
        "style": {
            "accent": "#1d7af2"
        }
    },
    "app_json": "{\n  \"schema\": \"tailapps/v0\",\n  \"app\": \"app-ranks\",\n  \"name\": \"App Ranks\",\n  \"description\": \"Where your app sits in the App Store's top 100, country by country, checked every hour on your Mac, with a notification when its best rank moves. The iPhone sees it too.\",\n  \"icon\": \"chart.line.uptrend.xyaxis\",\n  \"version\": 1,\n  \"permissions\": [\n    \"script:ranks.sh\",\n    \"net:rss.marketingtools.apple.com\",\n    \"notify\"\n  ],\n  \"settings\": {\n    \"app_id\": {\n      \"type\": \"text\",\n      \"label\": \"App Store id (the digits after id in its link)\",\n      \"required\": true,\n      \"platforms\": [\n        \"macos\"\n      ]\n    },\n    \"countries\": {\n      \"type\": \"text\",\n      \"label\": \"Countries (two-letter codes)\",\n      \"default\": \"us,gb,de,fr,jp,au,ca,pl\",\n      \"platforms\": [\n        \"macos\"\n      ]\n    },\n    \"chart\": {\n      \"type\": \"select\",\n      \"label\": \"Chart\",\n      \"options\": [\n        \"top-free\",\n        \"top-paid\"\n      ],\n      \"default\": \"top-free\",\n      \"platforms\": [\n        \"macos\"\n      ]\n    }\n  },\n  \"scripts\": {\n    \"ranks.sh\": \"#!/bin/sh\\n# Your app's place in Apple's public top-100 charts, one country at a time, as JSON:\\n# { \\\"countries\\\": [{ \\\"country\\\": \\\"gb\\\", \\\"rank\\\": 12, \\\"name\\\": \\\"\u2026\\\" }, \u2026], \\\"best\\\": 12, \\\"best_country\\\": \\\"gb\\\", \\\"charted\\\": 3, \\\"name\\\": \\\"\u2026\\\" }\\n# $1 = the App Store id (the digits after \\\"id\\\" in the app's link), $2 = countries like \\\"us,gb,pl\\\", $3 = top-free or top-paid.\\nid=\\\"$1\\\"\\nchart=\\\"$3\\\"\\ncase \\\"$id\\\" in ''|*[!0-9]*) echo \\\"The app id is the digits after \\\\\\\"id\\\\\\\" in its App Store link, like 1234567890\\\" >&2; exit 1 ;; esac\\ncase \\\"$chart\\\" in top-free|top-paid) ;; *) chart=top-free ;; esac\\nout=\\\"\\\"\\nfetched=0\\nfor c in $(printf '%s' \\\"$2\\\" | tr ',;' '  '); do\\n  c=$(printf '%s' \\\"$c\\\" | tr 'A-Z' 'a-z' | tr -cd 'a-z')\\n  [ ${#c} -eq 2 ] || continue\\n  if feed=$(curl -fsS --max-time 12 \\\"https://rss.marketingtools.apple.com/api/v2/$c/apps/$chart/100/apps.json\\\" 2>/dev/null); then\\n    fetched=$((fetched + 1))\\n  else\\n    feed='{}'\\n  fi\\n  row=$(printf '%s' \\\"$feed\\\" | jq -c --arg id \\\"$id\\\" --arg c \\\"$c\\\" '\\n    (.feed.results // []) as $r\\n    | { country: $c,\\n        rank: ($r | map(.id) | index($id) | if . == null then null else . + 1 end),\\n        name: ($r | map(select(.id == $id)) | .[0].name) }' 2>/dev/null) || row=\\\"{\\\\\\\"country\\\\\\\":\\\\\\\"$c\\\\\\\",\\\\\\\"rank\\\\\\\":null,\\\\\\\"name\\\\\\\":null}\\\"\\n  out=\\\"$out${out:+,}$row\\\"\\ndone\\n# No chart at all (offline, or Apple's feed is down) is an error, not \\\"out of the top 100\\\" everywhere.\\n[ \\\"$fetched\\\" -gt 0 ] || { echo \\\"Couldn't reach the App Store charts\\\" >&2; exit 1; }\\nprintf '[%s]' \\\"$out\\\" | jq -c '\\n  (map(select(.rank != null))) as $in\\n  | { countries: .,\\n      best: ($in | map(.rank) | min),\\n      best_country: (if ($in | length) > 0 then ($in | min_by(.rank) | .country) else null end),\\n      charted: ($in | length),\\n      name: ($in | map(.name) | .[0]) }'\\n\"\n  },\n  \"state\": {\n    \"latest\": {\n      \"type\": \"object\",\n      \"default\": {},\n      \"sync\": true\n    },\n    \"history\": {\n      \"type\": \"list\",\n      \"default\": [],\n      \"sync\": true\n    }\n  },\n  \"sources\": {\n    \"ranks\": {\n      \"script\": \"ranks.sh\",\n      \"args\": [\n        \"$settings.app_id\",\n        \"$settings.countries\",\n        \"$settings.chart\"\n      ],\n      \"every\": 3600,\n      \"timeout\": 120,\n      \"platforms\": [\n        \"macos\"\n      ],\n      \"on_change\": {\n        \"action\": \"checked\",\n        \"watch\": \"{$ranks.best} {$ranks.charted}\"\n      }\n    }\n  },\n  \"actions\": {\n    \"checked\": {\n      \"runs_on\": [\n        \"macos\"\n      ],\n      \"steps\": [\n        {\n          \"if\": \"$latest.at\",\n          \"then\": [\n            {\n              \"if\": \"$ranks.best\",\n              \"then\": [\n                {\n                  \"notify\": {\n                    \"title\": \"{$ranks.name | default:'Your app'} is #{$ranks.best}\",\n                    \"body\": \"Best place now, in {$ranks.best_country | upper} ({$ranks.charted} of your countries)\"\n                  }\n                }\n              ],\n              \"else\": [\n                {\n                  \"notify\": {\n                    \"title\": \"Out of the top 100\",\n                    \"body\": \"Not in the top 100 in any of your countries\"\n                  }\n                }\n              ]\n            }\n          ]\n        },\n        {\n          \"set\": {\n            \"latest\": {\n              \"best\": \"$ranks.best\",\n              \"best_country\": \"$ranks.best_country\",\n              \"charted\": \"$ranks.charted\",\n              \"name\": \"$ranks.name\",\n              \"countries\": \"$ranks.countries\",\n              \"at\": \"$now\"\n            }\n          }\n        },\n        {\n          \"push\": {\n            \"history\": {\n              \"at\": \"$now\",\n              \"best\": \"$ranks.best\"\n            }\n          },\n          \"at\": \"end\",\n          \"max\": 72\n        }\n      ]\n    },\n    \"check_now\": {\n      \"runs_on\": [\n        \"macos\"\n      ],\n      \"steps\": [\n        {\n          \"refresh\": \"ranks\"\n        }\n      ]\n    },\n    \"clear_history\": {\n      \"confirm\": \"Clear the rank history on all your devices?\",\n      \"steps\": [\n        {\n          \"set\": {\n            \"history\": []\n          }\n        }\n      ]\n    }\n  },\n  \"cards\": [\n    {\n      \"id\": \"main\",\n      \"layout\": {\n        \"column\": [\n          {\n            \"row\": [\n              {\n                \"stat\": \"$latest.best | map:{null:'\u2014'}\",\n                \"label\": \"Best rank\",\n                \"size\": \"xl\"\n              },\n              {\n                \"spacer\": true\n              },\n              {\n                \"stat\": \"$latest.charted | default:'0'\",\n                \"label\": \"Countries in the top 100\"\n              }\n            ],\n            \"align\": \"start\"\n          },\n          {\n            \"text\": \"{$latest.name | default:'Your app'} \u00b7 best in {$latest.best_country | upper}\",\n            \"size\": \"s\",\n            \"emphasis\": \"subtle\",\n            \"when\": \"$latest.best\"\n          },\n          {\n            \"chart\": \"$history | pluck:'best'\",\n            \"kind\": \"line\",\n            \"height\": \"s\",\n            \"hue\": \"blue\",\n            \"when\": \"$history | count\"\n          },\n          {\n            \"column\": [\n              {\n                \"list\": \"$latest.countries\",\n                \"empty\": \"No check yet. Set your app's id in Settings on your Mac.\",\n                \"item\": {\n                  \"cell\": \"$item.country | upper\",\n                  \"leading\": \"$item.country | flag\",\n                  \"subtitle\": \"$item.rank | map:{null:'Not in the top 100', else:'In the top 100'}\",\n                  \"trailing\": {\n                    \"badge\": \"#{$item.rank}\",\n                    \"tone\": \"$item.rank | tone:{good:'<=10', warn:'<=50', else:'neutral'}\",\n                    \"when\": \"$item.rank\"\n                  }\n                }\n              }\n            ],\n            \"style\": \"inset\"\n          }\n        ],\n        \"gap\": \"m\"\n      },\n      \"footer\": {\n        \"row\": [\n          {\n            \"text\": \"Checked {$latest.at | ago}\",\n            \"size\": \"s\",\n            \"emphasis\": \"subtle\",\n            \"when\": \"$latest.at\"\n          },\n          {\n            \"spacer\": true\n          },\n          {\n            \"button\": \"Check now\",\n            \"on\": \"check_now\",\n            \"style\": \"plain\",\n            \"disabled\": \"$running.check_now\",\n            \"platforms\": [\n              \"macos\"\n            ]\n          }\n        ],\n        \"align\": \"center\"\n      }\n    }\n  ],\n  \"views\": {\n    \"menubar\": {\n      \"icon\": \"chart.line.uptrend.xyaxis\",\n      \"label\": \"Rank {$latest.best | map:{null:'\u2014'}}\",\n      \"label_tone\": \"$latest.best | tone:{good:'<=10', else:'neutral'}\",\n      \"card\": \"main\",\n      \"in_menu\": \"row\"\n    },\n    \"floating\": {\n      \"card\": \"main\",\n      \"width\": \"default\"\n    }\n  },\n  \"style\": {\n    \"accent\": \"#1d7af2\"\n  }\n}\n",
    "files": []
}