From 5d952386f8a46a0beee281e11200ee2d875c3cb2 Mon Sep 17 00:00:00 2001 From: densnow <48718090+densnow@users.noreply.github.com> Date: Wed, 28 Aug 2024 13:59:25 +0100 Subject: [PATCH] Fix #30: create Windows desktop shortcut (#43) --------- Co-authored-by: Michel Wermelinger --- README.md | 30 +++++++++++++++--------------- install.ps1 | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index e601938..3269894 100644 --- a/README.md +++ b/README.md @@ -81,11 +81,18 @@ the software, if needed. Now proceed to the next section. ## 3 Usage On Windows, there are two ways of using the M269 notebooks, either from a terminal -or by creating a desktop shortcut. On Unix, use a terminal. +or by double clicking a desktop shortcut. On Unix, use a terminal. ### 3.1 Desktop shortcut (Windows only) -The `start.ps1` script and these instructions are originally by M269 tutor Bob Moore. +The installation process creates a shortcut on your desktop named `M269-start`. +If you double click this shortcut, a PowerShell window opens where Jupyter writes its log messages, +then your browser opens the Jupyter dashboard, listing the contents of your M269 folder. +If there’s a message about migrating to Notebook 7, click "don’t show anymore". +You can now continue reading Section 1.3 of the book to learn how to use Jupyter. + +**Note for tutors:** You can create additional shortcuts, each opening Jupyter in +a different start folder, e.g. the eTMA marking folder, by following these instructions: 1. Right click on the desktop. Select 'new shortcut'. Type `powershell`. Hit 'Next' and then 'Finish': 'powershell' gets automatically expanded to the full name of the program. @@ -93,22 +100,15 @@ The `start.ps1` script and these instructions are originally by M269 tutor Bob M 2. Right click on the new desktop icon and select 'Properties' to update the shortcut: 1. Modify the start-up folder to be your M269 folder. - 2. Append `-file start.ps1` to the target field. It should now read: - `C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file start.ps1`. + 2. Append `-file start.ps1 path/to/folder` to the target field + (if the path includes spaces, you must enclose it in quotes). It should now read: + `C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file start.ps1 path/to/folder`. 3. Optionally you can update the icon for the shortcut. To get a Jupyter icon instead of a PowerShell icon you can use - `%USERPROFILE%\venvs\m269-23j\Lib\site-packages\nbclassic\static\base\images\favicon.ico`. - -You should now be able to double click on the desktop shortcut to start Jupyter -in your M269 folder. First, a PowerShell window opens where Jupyter writes its log messages, -then your browser should open the Jupyter dashboard, listing the contents of your M269 folder. -If there’s a message about migrating to Notebook 7, click "don’t show anymore". -You can now continue reading Section 1.3 of the book to learn how to use Jupyter. + `%USERPROFILE%\venvs\m269-24j\Lib\site-packages\nbclassic\static\base\images\favicon.ico`. -**Note for tutors:** You can create multiple shortcuts, each opening Jupyter in -a different start folder, e.g. the eTMA marking folder. Follow the same steps -as above for each shortcut, but in step 2.2, append also the intended start folder: -`-file start.ps1 path/to/folder`. If the path includes spaces, you must enclose it in quotes. +We thank M269 tutor Bob Moore for creating the original version of `start.ps1` +and of these shortcut instructions. ### 3.2 Terminal (Windows and Unix) diff --git a/install.ps1 b/install.ps1 index a821624..839b463 100644 --- a/install.ps1 +++ b/install.ps1 @@ -118,5 +118,23 @@ if (-not (Test-Path -Path $CONFIG_FILE)) { } Add-Content -Path $CONFIG_FILE -Value $ALIASES -NoNewline +Write-Host "Adding desktop shortcut..." + +$Desktop = [System.Environment]::GetFolderPath('Desktop') +$ShortcutPath = Join-Path $Desktop "M269-start.lnk" +$TargetPath = "$FOLDER\start.ps1" + +$WScriptShell = New-Object -ComObject WScript.Shell +$Shortcut = $WScriptShell.CreateShortcut($ShortcutPath) +$Shortcut.TargetPath = "powershell.exe" +$Shortcut.Arguments = "-ExecutionPolicy Bypass -File `"$TargetPath`"" +$Shortcut.Description = "Start the M269 software" + +# set the icon for the shortcut (using the powershell icon) +$PowerShellExe = (Get-Command powershell.exe).Source +$Shortcut.IconLocation = "$PowerShellExe, 0" + +$Shortcut.Save() + Write-Host "Software has been installed." Write-Host "All done. Go to $SITE for further instructions."