蓝色天空.知识 · 实践 · 创造
我的收藏
在线代码实验室

运行 macOS 通用应用包路径、聚焦搜索快捷键与 Shell Command PATH 符号链接离线校验

PYTHONWindows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。explore-macos-install.py
explore-macos-install.py82 行
"""Offline VS Code macOS installation & Shell Command PATH verifier for Ch04 (macos-install)."""
import json

VERSION = "CPython 3.12.14 offline macOS bundle & PATH verifier"


def check(name, summary, expected, actual):
    return {
        "name": name,
        "summary": summary,
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def main():
    cases = []

    # Case 1: macOS universal archive, Applications drag target, Spotlight & OS matrix
    min_os = {
        "Windows": "Windows 7 64 位或更高版本",
        "macOS": "macOS 10.11 El Capitan 或更高版本",
        "Linux": "Ubuntu 16.04+, Debian 9+, Fedora 30+, CentOS 7+",
    }
    macos_flow = {
        "archive": "VSCode-darwin-universal.zip",
        "app_bundle": "Visual Studio Code.app",
        "install_path": "/Applications/Visual Studio Code.app",
        "spotlight_shortcut": "Command ⌘ + Space",
        "gatekeeper_confirm_button": "Open",
    }
    cases.append(
        check(
            "macos_bundle_and_os_requirements",
            "Verify macOS universal archive, /Applications bundle path, Spotlight shortcut, and OS matrix",
            {
                "os_count": 3,
                "archive": "VSCode-darwin-universal.zip",
                "install_path": "/Applications/Visual Studio Code.app",
                "spotlight_uses_cmd": True,
                "gatekeeper_confirm": "Open",
            },
            {
                "os_count": len(min_os),
                "archive": macos_flow["archive"],
                "install_path": macos_flow["install_path"],
                "spotlight_uses_cmd": "Command ⌘" in macos_flow["spotlight_shortcut"],
                "gatekeeper_confirm": macos_flow["gatekeeper_confirm_button"],
            },
        )
    )

    # Case 2: Shell Command: Install 'code' command in PATH symlink resolution
    symlink_target = "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code"
    symlink_link = "/usr/local/bin/code"
    path_list = ["/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin"]
    cases.append(
        check(
            "macos_shell_command_path_symlink",
            "Verify macOS Shell Command PATH symlink location and Command Palette invocation",
            {
                "palette_command": "Shell Command: Install 'code' command in PATH",
                "symlink_in_path": True,
                "target_inside_app_bundle": True,
                "macos_palette_shortcut": "⇧⌘P",
            },
            {
                "palette_command": "Shell Command: Install 'code' command in PATH",
                "symlink_in_path": "/usr/local/bin" in path_list and symlink_link.startswith("/usr/local/bin/"),
                "target_inside_app_bundle": symlink_target.startswith("/Applications/Visual Studio Code.app/"),
                "macos_palette_shortcut": "⇧⌘P",
            },
        )
    )

    print(json.dumps({"version": VERSION, "cases": cases}, ensure_ascii=False, indent=2))


if __name__ == "__main__":
    main()
本例需在 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程

运行环境:Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。

入口文件:projects/vscode-macos-install-lab/explore-macos-install.py

本地运行步骤快速上手
  1. 点击上方“保存源码”保存为 explore-macos-install.py,或下载右侧课程工程包。
  2. 确认本地已准备 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。。
  3. 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载

下载课程关联工程包:VS Code

课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2214.zip

下载课程关联工程包:VS Code

课程关联工程包(登记关联25章) · 含当前章节或实例 · mbskycom202612a2203.zip
SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习