回复 10# 867258173
以下代码本质没改变,只是稍稍修改了原来的代码。- @echo off&Title 生成Side Bar.sublime-menu的内容&setlocal EnableExtensions
- if not exist ".\Data\Packages\User\SideBarEnhancements\Open With" md ".\Data\Packages\User\SideBarEnhancements\Open With"
- SET "FilePath=.\Data\Packages\User\SideBarEnhancements\Open With\Side Bar.sublime-menu"
- if exist "%FilePath%" if not exist "%FilePath%.bak" copy /y "%FilePath%" "%FilePath%.bak" >nul
- .>"%FilePath%" 2>nul&call :head
- SET "Program=chrome.exe firefox.exe launcher.exe SafariPortable.exe Maxthon.exe TheWorld.exe 360se.exe 360chrome.exe baidubrowser.exe QQBrowser.exe SogouExplorer.exe LisectIE6.exe IETester.exe navigator.exe"
- FOR %%I IN (%Program%) DO for /f "delims=" %%J in ('DIR /S /B /A:-D "%%~I" 2^>nul') do if /I "%%~nxJ"=="%%~I" (set "ExePath=%%~J"&call set "application=%%ExePath:\=/%%"&SET "caption=%%~I"&call :Build)
- call :end
- (iconv.exe --help >NUL 2>nul)&&(for /f "usebackq" %%I in (`SET /P^="测试"^<NUL^|iconv.exe -f GB2312 -t java`) do if "%%I"=="\u6d4b\u8bd5" ((iconv.exe -f GBK -t UTF-8 "%FilePath%" > "%FilePath%.tmp")&(type "%FilePath%.tmp">"%FilePath%")&(del /f/q "%FilePath%.tmp")))
- notepad "%FilePath%"&Endlocal&exit
-
- :Build
- set /p= // This is [%caption%]<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= {"<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p= "caption": "%caption%",<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= "id": "side-bar-files-open-with-seamonkey","<nul>>"%FilePath%"&echo,>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= "command": "side_bar_files_open_with","<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= "args": {"<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= "paths": [],"<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p= "application": "%application%", // WINNT<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= "extensions":"", //open all even folders"<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= "args":[]"<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= },"<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= "open_automatically" : false // will close the view/tab and launch the application"<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= },"<nul>>"%FilePath%"&echo,>>"%FilePath%"&echo,>>"%FilePath%"&echo,>>"%FilePath%"
- goto :eof
-
- :end
- set /p"= {"caption":"-"}"<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= ]"<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= }"<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"=]"<nul>>"%FilePath%"&echo,>>"%FilePath%"
- goto :eof
-
- :head
- set /p"=["<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= {"id": "side-bar-files-open-with","<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= "children":"<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= ["<nul>>"%FilePath%"&echo,>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= //application 1"<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= {"<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= "caption": "Photoshop","<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= "id": "side-bar-files-open-with-photoshop","<nul>>"%FilePath%"&echo,>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= "command": "side_bar_files_open_with","<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= "args": {"<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= "paths": [],"<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= "application": "Adobe Photoshop CS5.app", // OSX"<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= "extensions":"psd^|png^|jpg^|jpeg", //any file with these extensions"<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= "args":[]"<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= },"<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= "open_automatically" : false // will close the view/tab and launch the application"<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= },"<nul>>"%FilePath%"&echo,>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= //separator"<nul>>"%FilePath%"&echo,>>"%FilePath%"
- set /p"= {"caption":"-"},"<nul>>"%FilePath%"&echo,>>"%FilePath%"&echo,>>"%FilePath%"&echo,>>"%FilePath%"
- goto :eof
- :::::::::::::::::::::::::::::::::::::::::::
复制代码 说明:
1. 生成的编码为ANSI,全英文路径文件名直接支持UTF-8环境;
2. 生成的换行方式为CR+LF(Windows),要使用LF(Unix),修改:sublime编辑器》查看》行尾》Unix;
3. 生成的路径分隔符为”/“,要使用“\\”,修改程序中的 "application=%%ExePath:\=/%%" 为 "application=%%ExePath:\=\\%%";
4. 已定义14个浏览器,可以根据需要手动直接修改程序中“SET Program=”后的赋值;
5. 本程序放到目录“Data”的同级运行。
手动更改ANSI编码为UTF-8编码:
sublime编辑器》打开文件》Side Bar.sublime-menu;
文件》设置文件编码》UTF-8;
文件》保存编码》UTF-8;
标签页》Side Bar.sublime-menu》关闭;
文件》打开最近的文件》Side Bar.sublime-menu。
每次这样很麻烦!把iconv.exe放到本程序一起即可(iconv.exe是知名的iconv库在windows下的命令行编码转换工具,谷歌百度一大把)。
以上是实际使用时的完整代码,在XP上测试通过,你可试试,祝你好运!
::::::::::::::::::::::::::::::::::::::::::: |