共用方式為


使用適用於 Windows 應用程式的 macOS 命令行介面

Windows App for macOS 提供命令行介面(CLI),可讓您用來執行各種工作作為使用者介面的替代方案。 針對某些工作,使用 CLI 可以更有效率,特別是當您需要多次執行相同的工作或自動化工作時。 在macOS上,您可以使用內建 的終端 機應用程式來執行 CLI 命令。

本文說明如何使用適用於 Windows 應用程式的 macOS CLI。

先決條件

您必須先安裝適用於 macOS 的 Windows 應用程式,才能在 macOS 上使用適用於 Windows 應用程式的 CLI。 如需詳細資訊,請參閱 開始使用 Windows 應用程式來連線到裝置和應用程式

執行命令

若要使用適用於 Windows 應用程式的 CLI 執行命令:

  1. 在您的 macOS 裝置上開啟 終端 機應用程式。

  2. 包含 Windows 應用程式可執行檔案的預設路徑是 /Applications/Windows App.app/Contents/MacOS,這會區分大小寫。 執行下列命令來變更此目錄:

    cd '/Applications/Windows App.app/Contents/MacOS'
    
  3. 您可以從這個位置執行具有不同模組的 Windows 應用程式可執行檔。 若要檢查您可以執行命令,請執行下列命令來列印說明訊息:

    ./'Windows App' --script
    

    輸出如下所示:

    Usage:
    
      --script <module> <parameters>
    
      Modules:
    
        bookmark  Create, edit or delete a connection bookmark.
        feed      Subscribe to a resource feed, or edit or delete a subscription.
        gateway   Create, edit or delete a Remote Desktop gateway.
        defaults  Display client settings configurable through the defaults command
    
      To get help for a specific module:
    
        --script <module> help
    
      Examples:
    
        --script bookmark help
        --script feed help
        --script gateway help
    
  4. 可用的模組會列在上一個命令的輸出中。 您可以新增模組名稱,後面接著 help,以取得每個模組的完整語法,如上一個步驟的輸出所示。 例如,若要列印 bookmark 模組的說明資訊,請執行下列命令:

    ./'Windows App' --script bookmark help
    

    輸出如下所示:

    Usage:
    
      --script bookmark <command> <unique ID> <parameter>
    
      Commands:
    
        write   Create or edit a connection bookmark.
        delete  Delete a connection bookmark.
        list    List all stored bookmarks.
        export  Output a bookmark as a formatted string.
    
      To get help for a specific command:
    
        --script bookmark <command> help
    
      Examples:
    
        --script bookmark write help
        --script bookmark delete help
        --script bookmark list help
        --script bookmark export help
    
  5. 最後,您也可以逐一查看每個模組的每個命令,藉由新增命令名稱來列印說明資訊,後面接著 help,如上一個步驟的輸出所示

每個模組和命令的 Windows App 中可用的說明資訊會提供使用指示、參數詳細數據和如何使用每個命令的範例。

模組秘訣

下列秘訣可協助您更有效地使用適用於 Windows 應用程式的 CLI:

  • 針對需要唯一識別碼的命令,您可以在uuidgen機應用程式中執行 命令,以產生唯一標識符。

  • 若要編輯儲存的書籤,請輸入與您用來建立書籤的相同唯一 ID。 write 命令會使用新的資訊來更新現有的書籤。

  • 針對 feed 模組,只能新增使用使用者名稱和密碼驗證的遠端桌面服務環境。 您無法新增 Azure 虛擬桌面、Windows 365 或 Microsoft Dev Box 資源,因為它使用宣告型驗證。