Open Desktop Shortcuts (Windows)
How to invoke in CoPaw (read this first)
- The YAML field
name: open_desktop_shortcutsis the skill folder id for discovery — not a callable tool exposed to the model asopen_desktop_shortcuts(...). - There is no function like
open_desktop_shortcutswith parameters such asshortcut: "微信". Calling that name causesFunctionNotFoundError. - To actually run the steps below, use the built-in tool
execute_shell_commandwith acommandstring containing the PowerShell one-liner (set$MATCHinside that string for a single shortcut). Do not invent another tool name. - Example shape:
execute_shell_command→command: paste the one-liner from Open one shortcut (by name), with$MATCH="微信"or$MATCH="WeChat"depending on the real file BaseName on disk.
Use PowerShell (these snippets are not cmd.exe one-liners). If your shell is cmd, run via powershell -NoProfile -Command "...", or write a .ps1 and run powershell -NoProfile -ExecutionPolicy Bypass -File script.ps1 (see CoPaw Windows shell rules).
Scope
Scripts below search these roots (missing folders are skipped):
| Location | Path source |
|---|---|
| Current user Desktop | [Environment]::GetFolderPath('Desktop') |
| All users / Public Desktop | [Environment]::GetFolderPath('CommonDesktopDirectory') |
| Current user Start Menu → Programs | [Environment]::GetFolderPath('Programs') |
| All users Start Menu Programs | [Environment]::GetFolderPath('CommonPrograms') |
- Recursive under each root (so subfolders under Start Menu are included).
- Files:
*.lnkand*.url(internet shortcuts). For.url, the script usesStart-Processon the file so the system opens the URL like double‑click. - Not covered: Taskbar pins / tiles with no
.lnkin these trees, UWP-only entries, or items outside the four roots above. - Single target only: This skill does not describe “open every shortcut at once”. Each run launches at most one matching file (first hit); do not use it to mass-launch all shortcuts.
Open one shortcut (by name)
When the user asks to open one shortcut (e.g. “open Chrome”, “launch 微信”, “run the shortcut named X”):
- Choose a substring
MATCHthat should appear in the file BaseName (name without extension), for.lnkor.url. MATCHmust be non-empty.-like "*$MATCH*"treats*?[insideMATCHas wildcard characters. If needed, list files first (see below).
Single line (set MATCH then run — only the first matching file is launched; roots are scanned in table order, first hit wins):
$MATCH="WeChat"; if ([string]::IsNullOrWhiteSpace($MATCH)) { throw "MATCH must not be empty" }; $roots=@([Environment]::GetFolderPath('Desktop'),[Environment]::GetFolderPath('CommonDesktopDirectory'),[Environment]::GetFolderPath('Programs'),[Environment]::GetFolderPath('CommonPrograms')); $s=New-Object -ComObject WScript.Shell; $one=$null; foreach($r in $roots){ if(-not (Test-Path -LiteralPath $r)){continue}; $one=Get-ChildItem -LiteralPath $r -Recurse -File -ErrorAction SilentlyContinue | Where-Object { $_.Extension -match '\.(lnk|url)$' -and $_.BaseName -like "*$MATCH*" } | Select-Object -First 1; if($one){break} }; if($one){ $p=$one.FullName; try { if($one.Extension -match '\.url$'){ Start-Process -FilePath $p -ErrorAction SilentlyContinue } else { $t=$s.CreateShortcut($p).TargetPath; if($t){ Start-Process $t -ErrorAction SilentlyContinue } else { Start-Process $p -ErrorAction SilentlyContinue } } } catch { try { Start-Process $p -ErrorAction SilentlyContinue } catch {} } }
- If multiple files match the pattern, only one is started (first found). If the wrong program opens, list files (below), then use a tighter
MATCH, or ask the user which name to use. - If nothing launches: try another substring for BaseName (e.g.
微信vsWeChat), or list files across roots (example one-liner):
$roots=@([Environment]::GetFolderPath('Desktop'),[Environment]::GetFolderPath('CommonDesktopDirectory'),[Environment]::GetFolderPath('Programs'),[Environment]::GetFolderPath('CommonPrograms')); foreach($r in $roots){ if(Test-Path -LiteralPath $r){ Get-ChildItem -LiteralPath $r -Recurse -File -ErrorAction SilentlyContinue | Where-Object { $_.Extension -match '\.(lnk|url)$' } | Select-Object FullName,BaseName } }
Limitations
.lnk:CreateShortcut(...).TargetPathignores arguments / working directory / “run as admin”; for closest behavior to double‑click, you can useStart-Process -FilePath $_.FullNameinstead (same paths as above)..url: Opens with the default browser viaStart-Processon the file; not every site behaves like in-app webview.- Start Menu recurse can be slow on large profiles; use a narrower
$MATCHwhen possible. - Pinned-only items with no file under the four roots are still not reachable by these scripts.
Source: hyqibot/token-free-openclaw — distributed by TomeVault.