Skip to content

Commit ec134b0

Browse files
authored
Update setup_autostart.bat
1 parent d9d9e7f commit ec134b0

File tree

1 file changed

+80
-55
lines changed

1 file changed

+80
-55
lines changed

setup_autostart.bat

Lines changed: 80 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,83 @@
1-
echo off
2-
setlocal
3-
4-
:: ----------------------------------------------------
5-
:: 1. DEFINITIONS
6-
:: ----------------------------------------------------
7-
:: The permanent path where the script will be stored
8-
set SCRIPT_DIR=C:\Scripts
9-
:: Name of the PowerShell script containing the core command
10-
set PS_SCRIPT_NAME=spicetify_install.ps1
11-
:: Name of the Batch wrapper script that lands in Startup
12-
set WRAPPER_SCRIPT_NAME=spicetify_start.bat
13-
:: The path to the current user's Startup folder
14-
set STARTUP_FOLDER="%%APPDATA%%\Microsoft\Windows\Start Menu\Programs\Startup"
15-
16-
:: ----------------------------------------------------
17-
:: 2. CREATE SCRIPT DIRECTORY
18-
:: ----------------------------------------------------
19-
echo Creating script directory: %SCRIPT_DIR%
20-
if not exist "%SCRIPT_DIR%" mkdir "%SCRIPT_DIR%"
21-
22-
:: ----------------------------------------------------
23-
:: 3. CREATE POWERSHELL INSTALL FILE
24-
:: ----------------------------------------------------
25-
echo Writing PowerShell command to %SCRIPT_DIR%\%PS_SCRIPT_NAME%
1+
@echo off
2+
setlocal enabledelayedexpansion
3+
4+
:: ====================================================================
5+
:: 1. Initial User Confirmation (Y/N)
6+
:: ====================================================================
7+
ECHO ====================================================================
8+
ECHO Spicetify Autostart Setup: Creating files and setting up autostart.
9+
ECHO ====================================================================
10+
CHOICE /C YN /M "Do you want to start the installation?"
11+
IF ERRORLEVEL 2 GOTO end
12+
13+
:install
14+
ECHO.
15+
ECHO --- Starting Spicetify Autostart Setup ---
16+
17+
:: --------------------------------------------------------------------
18+
:: 2. Setup Directory
19+
:: --------------------------------------------------------------------
20+
ECHO Creating C:\Scripts directory...
21+
MD C:\Scripts 2>NUL
22+
23+
:: --------------------------------------------------------------------
24+
:: 3. Create spicetify_install.ps1 (The Core Command)
25+
:: This script executes the official Spicetify install/update command.
26+
:: --------------------------------------------------------------------
27+
ECHO Creating Core PowerShell script (spicetify_install.ps1)...
28+
(
29+
ECHO iwr -useb https://raw.githubusercontent.com/spicetify/cli/main/install.ps1 ^| iex
30+
) > C:\Scripts\spicetify_install.ps1
31+
32+
:: --------------------------------------------------------------------
33+
:: 4. Create spicetify_start.bat (The Silent Wrapper)
34+
:: This Batch script runs the PowerShell file invisibly every time.
35+
:: --------------------------------------------------------------------
36+
ECHO Creating Silent Wrapper script (spicetify_start.bat)...
2637
(
27-
echo iwr -useb https://raw.githubusercontent.com/spicetify/cli/main/install.ps1 ^| iex
28-
) > "%SCRIPT_DIR%\%PS_SCRIPT_NAME%"
38+
ECHO @echo off
39+
ECHO start /min powershell.exe -NoProfile -ExecutionPolicy Bypass -File "C:\Scripts\spicetify_install.ps1"
40+
) > C:\Scripts\spicetify_start.bat
2941

30-
:: ----------------------------------------------------
31-
:: 4. CREATE WRAPPER BATCH FILE (for Autostart)
32-
:: ----------------------------------------------------
33-
echo Writing wrapper batch script to %SCRIPT_DIR%\%WRAPPER_SCRIPT_NAME%
42+
:: --------------------------------------------------------------------
43+
:: 5. Create Autostart Shortcut (.lnk)
44+
:: Using VBScript is the most reliable way to create a shortcut in Batch.
45+
:: --------------------------------------------------------------------
46+
ECHO Creating Startup shortcut...
3447
(
35-
echo @echo off
36-
echo start /min powershell.exe -ExecutionPolicy Bypass -File "%SCRIPT_DIR%\%PS_SCRIPT_NAME%"
37-
) > "%SCRIPT_DIR%\%WRAPPER_SCRIPT_NAME%"
38-
39-
:: ----------------------------------------------------
40-
:: 5. CREATE SHORTCUT IN THE STARTUP FOLDER
41-
:: ----------------------------------------------------
42-
echo Creating shortcut in the Startup folder: %STARTUP_FOLDER%
43-
:: The target is the wrapper script
44-
set TARGET_PATH="%SCRIPT_DIR%\%WRAPPER_SCRIPT_NAME%"
45-
:: The name of the shortcut
46-
set LINK_NAME="Spicetify Autostart.lnk"
47-
48-
:: Use PowerShell to create the shortcut, as Batch cannot do this natively
49-
powershell.exe -ExecutionPolicy Bypass -Command "$WshShell = New-Object -comObject WScript.Shell; $Shortcut = $WshShell.CreateShortcut(%STARTUP_FOLDER%\%LINK_NAME%); $Shortcut.TargetPath = %TARGET_PATH%; $Shortcut.Save()"
50-
51-
:: ----------------------------------------------------
52-
:: 6. COMPLETION
53-
:: ----------------------------------------------------
54-
echo.
55-
echo The Spicetify autostart routine has been successfully set up.
56-
echo It will execute on the next user login.
57-
echo.
58-
pause
48+
ECHO Set oWS = WScript.CreateObject("WScript.Shell")
49+
ECHO sLinkFile = "%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup\Spicetify Autostart.lnk"
50+
ECHO Set oLink = oWS.CreateShortcut(sLinkFile)
51+
ECHO oLink.TargetPath = "C:\Scripts\spicetify_start.bat"
52+
ECHO oLink.Save
53+
) > "C:\Scripts\CreateShortcut.vbs"
54+
55+
CSCRIPT //Nologo "C:\Scripts\CreateShortcut.vbs"
56+
DEL "C:\Scripts\CreateShortcut.vbs"
57+
58+
:: --------------------------------------------------------------------
59+
:: 6. Initial Execution
60+
:: This runs the core install process immediately for the first time.
61+
:: This is where the user must type 'Y' for the PowerShell provider.
62+
:: --------------------------------------------------------------------
63+
ECHO.
64+
ECHO --- Running initial Spicetify installation (Check for 'Y' prompt!) ---
65+
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "C:\Scripts\spicetify_install.ps1"
66+
ECHO Initial installation complete.
67+
68+
:: --------------------------------------------------------------------
69+
:: 7. Finish
70+
:: --------------------------------------------------------------------
71+
ECHO.
72+
ECHO Setup complete! The routine will start automatically upon next login.
73+
PAUSE
74+
EXIT /B 0
75+
76+
:: ====================================================================
77+
:: END Labels
78+
:: ====================================================================
79+
:end
80+
ECHO.
81+
ECHO Installation cancelled by user.
82+
PAUSE
83+
EXIT /B 1

0 commit comments

Comments
 (0)