Instantly share code, notes, and snippets.
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
-
Save amitkeret/c21963b847ce9676ff3e97dbf252ebc1 to your computer and use it in GitHub Desktop.
Bash script to display menu (and submenus) with choices
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @echo off | |
| echo. | |
| echo Starting Caffeine . . . | |
| Start "" caffeine64.exe | |
| timeout /3 5 >NUL 2>&1 | |
| echo Stopping unwanted processes . . . | |
| taskkill /f /im process1.exe >NUL 2>&1 | |
| taskkill /f /im process2.exe >NUL 2>&1 | |
| timeout /t 3 >NUL 2>&1 | |
| set "FLAG=%USERPROFILE%\Documents\START_first_run" | |
| if exist "%FLAG%" goto :menu | |
| echo FIRST RUN! Running one-time actions . . . | |
| echo Temp files location: %USERPROFILE%\AppData\Local\Temp | |
| :: Windows dark mode | |
| Start "" ms-settings:colors | |
| :: Chrome dark mode | |
| Start "" "C:\Program Files\Google\Chrome\Application\chrome.exe" "https://chromewebstore.google.com/detail/dark-mode/dmghijelimhndkbmpgbldicpogfkceaj" | |
| :: Chrome passwords | |
| setlocal EnableExtensions DisableDelayedExpansion | |
| set "PASSWORDS=%TEMP%\chrome_password_import_%RANDOM%.csv" | |
| > "%PASSWORDS%" echo name,url,username,password | |
| call :addpass "site1" "https://example1.com" "****" "****" | |
| call :addpass "site1" "https://example2.com" "****" "****" | |
| timeout /t 1 /nobreak >nul | |
| echo Temporary passwords CSV file ready. Goto chrome://password-manager/settings | |
| pause | |
| del /f /q "%PASSWORDS%" >nul 2>&1 | |
| endlocal | |
| :: Chrome bookmarks | |
| setlocal EnableExtensions DisableDelayedExpansion | |
| set "BOOKMARKS=%TEMP%\chrome_bookmarks_%RANDOM%.html" | |
| > "%BOOKMARKS%" echo ^<!DOCTYPE NETSCAPE-Bookmark-file-1^>^<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"^>^<TITLE^>Bookmarks^</TITLE^>^<H1^>Bookmarks^</H1^>^<DL^>^<p^>^<DT^>^<H3 ADD_DATE="0" LAST_MODIFIED="0" PERSONAL_TOOLBAR_FOLDER="true"^>Bookmarks bar^</H3^>^<DL^>^<p^> | |
| call :add_bookmark_folder "folder1" | |
| call :add_bookmark "site1" "https://example1.com" | |
| call :add_bookmark "site1" "https://example2.com" | |
| call :end_bookmark_folder | |
| call :add_bookmark "site3" "https://example3.com" | |
| >> "%BOOKMARKS%" echo ^</DL^>^<p^>^</DL^>^<p^> | |
| timeout /t 1 /nobreak >nul | |
| echo Temporary bookmarks file ready. Goto chrome://bookmarks | |
| pause | |
| del /f /q "%BOOKMARKS%" >nul 2>&1 | |
| endlocal | |
| :: Create the flag only after first-run actions succeed | |
| > "%FLAG%" echo First run completed: %DATE% %TIME% | |
| attrib +h "%FLAG%" | |
| timeout /3 5 >NUL 2>&1 | |
| goto :menu | |
| :addpass | |
| >> "%PASSWORDS%" echo "%~1","%~2","%~3","%~4" | |
| exit /b | |
| :add_bookmark | |
| >> "%BOOKMARKS%" echo ^<DT^>^<A HREF="%~2"^>%~1^</A^> | |
| exit /b | |
| :add_bookmark_folder | |
| >> "%BOOKMARKS%" echo ^<DT^>^<H3 ADD_DATE="0" LAST_MODIFIED="0"^>%~1^</H3^> | |
| >> "%BOOKMARKS%" echo ^<DL^>^<p^> | |
| exit /b | |
| :end_bookmark_folder | |
| >> "%BOOKMARKS%" echo ^</DL^>^<p^> | |
| exit /b | |
| :menu | |
| set choice=0 | |
| cls | |
| echo. | |
| echo Menu: | |
| echo 1. Program1 =^> | |
| echo 2. Program2Singleton =^> | |
| echo 3. Websites =^> | |
| echo. | |
| echo 00. EDIT THIS SCRIPT | |
| echo 9. LOG OFF | |
| set /p choice=Enter your choice: | |
| if "%choice%"=="1" goto prog1 | |
| if "%choice%"=="2" goto singleton | |
| if "%choice%"=="3" goto web | |
| if "%choice%"=="00" goto edit | |
| if "%choice%"=="9" goto logoff | |
| echo Choose a valid option... | |
| timeout /t 2 >NUL 2>&1 | |
| goto menu | |
| :prog1 | |
| echo. | |
| echo Starting... | |
| Start "" "C:\Program Files\some\program\path.exe" | |
| timeout /t 5 >NUL 2>&1 | |
| goto menu | |
| :singleton | |
| :: find the process; if exists, switch to the process, otherwise launch | |
| tasklist /FI "IMAGENAME eq singleton.exe" | find /I "singleton.exe" >NUL | |
| if errorlevel 1 ( | |
| :: replace singleton.exe with actual filename | |
| Start "" "C:\Program Files\some\program\singleton.exe" | |
| ) else ( | |
| :: replace SingletonProgram with actual process name | |
| powershell -command ^ | |
| "(Get-Process 'SingletonProgram' -ErrorAction SilentlyContinue | Where-Object {$_.MainWindowHandle -ne 0} | Select-Object -First 1).MainWindowHandle | ForEach-Object {Add-Type '[DllImport(\"user32.dll\")]public static extern bool SetForegroundWindow(IntPtr hWnd);' -Name Win32 -Namespace Native; [Native.Win32]::SetForegroundWindow($_)}" | |
| ) | |
| timeout /t 5 >NUL 2>&1 | |
| goto menu | |
| :web | |
| set choice=0 | |
| cls | |
| echo. | |
| echo Menu ^> Websites: | |
| echo 1. Website1 | |
| echo 2. Website2 | |
| echo. | |
| echo 9. ^<= BACK | |
| set /p choice=Enter your choice: | |
| if "%choice%"=="1" Start "" "C:\Program Files\Google\Chrome\Application\chrome.exe" "https://website1.com" | |
| if "%choice%"=="2" Start "" "C:\Program Files\Google\Chrome\Application\chrome.exe" "https://website2.com" | |
| if "%choice%"=="9" goto menu | |
| timeout /t 2 >NUL 2>&1 | |
| goto web | |
| :edit | |
| Start "" notepad.exe "%~dp0menu.bat" | |
| goto menu | |
| :logoff | |
| echo. | |
| set /p choice=Log off? (y/N) | |
| if "%choice%"=="y" goto exit | |
| if "%choice%"=="Y" goto exit | |
| goto menu | |
| :exit | |
| echo. | |
| echo Exiting... | |
| taskkill /f /im caffeine64.exe >NUL 2>&1 | |
| taskkill /f /im chrome.exe >NUL 2>&1 | |
| timeout /t 5 >NUL 2>&1 | |
| echo Logging off... | |
| shutdown /l |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment