Monday, July 8, 2019

Error handling for dnote & snote

After reviewing the current progress of both dnote and nnote. I've decided to break down the scripts into separate functions, subscribing to the idea of micro processes, as opposed to larger monolithic scripts.

However, I did modify the existing scripts to catch / error handle both x64-bit and x86-bit applications; below is the source code I utilized for both dnote and nnote (specifically the Daily Note version, obviously for the Named Note version, I modified for the $NamedNotesDir & $NamedNote variables).

The next iterations of these scripts will include creating separate functions. First for determining the type of note (daily or named), then creating/modifying the specified note, and finally for opening/calling the specified note.


1
2
3
4
5
6
7
8
9
try { 
    Start-Process -FilePath ((Get-ChildItem Env:\ProgramFiles).Value + '\Notepad++\notepad++.exe') -Argument ($DailyNotesDir + $Date + ".txt")
}
catch {
    Start-Process -FilePath ((Get-ChildItem Env:\ProgramFiles`(x86`)).Value + '\Notepad++\notepad++.exe') -Argument ($DailyNotesDir + $Date + ".txt")
}
finally {
    Write-Host "Ensure Notepad++ is installed in the default location" -ForegroundColor Red -BackgroundColor Black
}

Tuesday, July 2, 2019

Take Note (named)!

In the last blog post, I published a short script to create / append the date/time to a simple text file. Which I use to keep track of tasks I've worked on throughout the day. However, what if I wanted to keep notes while training on a particular product, or keep notes on a client project. Digging through dozens of daily note files could become unwieldy. As they say on TV, "There's gotta be a better way!" And so there is, and here's my shot at it:

The same caveats from the last blog post apply here (won't detect x86-bit applications, if installed on a x64-bit OS; I'm using an auto-save plug-in for Notepad++, so no data is lost; and you must create a "notes\named" directory in your Documents folder, or change that variable to your desired path).

In the next iteration, I want to create a single application that detects whether or not you've supplied a name for the note, and if not create a daily note; and provide error handling for x86-bit applications on x64-bit OS's.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<#
####################
Author: Sam Dye
Date: 2019-07-02
Version: 1

####################
Pre-requisites:
1) Add script location to "Path" environment variable
2) Set PowerShell Execution Policy to RemoteSigned
3) Launch "Run.exe" and type: "nnote.ps1"
#>

param(
[Parameter(Mandatory=$true)]
[string]$NamedNote
)

$DateTime = Get-Date -UFormat %Y-%m-%d.%H:%M
$NamedNotesDir = ("C:\Users\" + ((Get-ChildItem Env:\USERNAME).Value) + "\Documents\notes\named\")

Add-Content -Path ($NamedNotesDir + $NamedNote + ".txt") `
"
#=====================#
$($DateTime)
#=====================#"

Start-Process -FilePath ((Get-ChildItem Env:\ProgramFiles).Value + '\Notepad++\notepad++.exe') -Argument ($NamedNotesDir + $NamedNote + ".txt")