![]()
From web link to Everything on your local system
Everything은 내 PC에 있는 파일을 거의 실시간으로 검색해주는 아주 유용한 Windows용 유틸리티다.
인트라넷 웹페이지에서 텍스트를 카피하고 everything에 붙여 넣어 로컬 파일을 찾는 작업을 가끔씩 반복하는데
웹페이지의 링크를 통해 everything에 검색어를 전달하면 어떨까 하는 생각이 들었다.
예를 들면 아래와 같은 링크를 클릭하면 everything이 실행되어 2024년 보고서라는 검색어가 입력되는 식이다.
<a href="everything://2024년 보고서">2024년 보고서</a>작동 메커니즘
브라우저에서 인식할 수 있도록 custom scheme을 만들어 사용하는게 핵심이다.
flowchart TD subgraph Browser link[a href=everything://search-term] end PowerShell.script subgraph Everything search[search-term] end link -.->|custom scheme handler| PowerShell.script -.->|launch| search
셋업
1. 검색어를 everything에 전달해 줄 PowerShell file 작성
custom scheme 콜백을 받아서 검색어를 추출하고 everything을 실행시키는 역할이다.
- callback 받은 URL은 URL decode 해야한다. batch에서는 복잡한 문제이므로 PowerShell을 사용했다.
인터넷에서 구한 PowerShell 코드 실행은 주의 요망!
PowerShell(
*.ps1) 파일은 보안상 디폴트로 실행이 막혀있다.PowerShell
*.ps1파일을 실행하려면 시스템의 execution policy를 변경해한다.
아래 내용의 파일을 적당한 위치에 저장한다.
예) everything-scheme.ps1
param (
[string]$url
)
# Function to URL decode
function UrlDecode {
param ([string]$str)
Add-Type -AssemblyName System.Web
return [System.Web.HttpUtility]::UrlDecode($str)
}
try
{
# Remove the 'everything://' prefix from the URL
$search = $url -replace '^everything://', ''
# Remove trailing slashes, new lines from the search string
$search = $search.TrimEnd('/', [char]13, [char]10)
# URL decode the search string
$search = UrlDecode $search
# Read-Host -Prompt "Search term: [$search]"
# everything의 설치 경로가 다른 경우 수정
& "C:\Program Files\Everything\Everything.exe" -search $search
}
catch {
Write-Host "An error occurred: $_"
Read-Host -Prompt "Press Enter to exit"
}(참고) batch 버전
최초 작성했던 Batch 버전. URL decode가 안됨. 특수문자는 정상적으로 전달이 안될 것임.
Batch version.
Registry 이름 바꾸는 것 잊지 말자.@echo off
:: Extract the search string from the URL
set "url=%~1"
set "search=%url:everything://=%"
:: Remove trailing slashes from the search string
:removeTrailingSlash
if not "%search%"=="" (
if "%search:~-1%"=="/" (
set "search=%search:~0,-1%"
goto removeTrailingSlash
)
)
:: Launch Everything with the modified search string
"C:\Program Files\Everything\Everything.exe" -search "%search%"2. 윈도 Registry에 커스텀 스킴(everything://) 등록
everything://이라는 임의의 새로운 custom scheme을 등록한다.
레지스트리 경로는 아래와 같다. 맨 마지막 줄의 경로에 위에서 생성한 batch 파일 경로를 입력한다.
HKEY_CLASSES_ROOT
└── everything
├── (Default) = "URL:Everything Protocol"
├── URL Protocol = ""
└── shell
└── open
└── command
└── (Default) = powershell.exe -ExecutionPolicy Bypass -File "C:\path\to\everything-scheme.ps1" "%1"
등록 따라하기
regedit열기 (Win+R 누른 후regedit엔터)HKEY_CLASSES_ROOT하위에everything키 생성everything선택 후(기본값)에URL:Everything Protocol입력(필수는 아님)everything선택 후새로 만들기 > 문자열 값,URL Protocol추가. 값은 빈 값으로 유지everything하위에shell > open > command순으로 Key 추가command의(기본값)에powershell.exe -ExecutionPolicy Bypass -File "C:\path\to\everything-scheme.ps1" "%1"세트-WindowStyle Hidden을 추가해봤으나 터미널 윈도는 항상 뜨는 것 같다.
테스트
테스트용 링크
위 링크를 눌렀을 때 테스트라는 스트링이 everything에 전달되는지 확인한다.