Launch-Software "Run Anything from a Plain Text Link"
Launch applications from links written in a text file.
Introduction
Summary: This is the article of developing “Invoke-Link (Alias:
i
),” a PowerShell script for CLI that launches applications from links written in a text file.
Windows shortcut files are convenient. By registering frequently used applications, web links, and file paths, you gain quick access to them. You can casually place these shortcut files on your desktop or in any folder.
However, I’ve found some usability issues with these shortcut files. For instance, creating them can be a bit of a hassle. We can’t register multiple links in a single shortcut to launch them simultaneously. Moreover, because shortcut files (.lnk
) are binary, tracking changes using version control systems like Git becomes difficult.
Ideally, I wanted to write links in a simple text file and execute them directly. With this in mind, I developed the PowerShell script “Invoke-Link
(Alias:i
)”. While it’s a small improvement, it can be a subtle yet helpful way to minimize those brief interruptions in your workflow or train of thought caused by momentarily wondering, “Now, where did I save that file?”
Prerequisites
- ✓ A custom script: Installing pwsh-sketches
- ✓ The tested environment can be found here
Solving the Problem
1. Understanding the Problem
Let’s summarize the issues regarding Windows shortcut files (.lnk
):
Benefits/Advantages
Category | Benefits | Approach |
---|---|---|
Launching & Placement | - Quickly launch applications and files. - Can be placed anywhere. - Can be launched without leaving the current directory (by using a dedicated links folder). |
Leverage the existing advantages while integrating text file management to maintain immediate execution. |
Disadvantages/Issues
Category | Issue | Approach |
---|---|---|
Creation Effort | Creating .lnk files is cumbersome. |
Transition to a text file format to simplify the creation of links. |
Managing Multiple Links | A single shortcut file cannot register multiple links; it is not possible to launch multiple links at once. | Record multiple links in one text file and implement a mechanism for batch launching. |
Version Control | Being in binary format, managing differences in Git or other version control systems is challenging. | Shift to text-based management to facilitate tracking and sharing differences in version control systems. |
Platform Dependency | .lnk files are dependent on the Windows OS. |
Transition to a text file format to achieve platform-independent link management. |
2. Devising a Plan
Below is the implementation plan for managing and executing links using a text file:
Challenge | Proposed Plan |
---|---|
Maintaining Quick Launch & Convenience | Build a system that preserves the benefits of shortcut files, allowing you to launch applications and files without leaving your current directory. |
Adopting a Text File Format | Manage link information using text files instead of binary formats, making version control (e.g., with Git) much easier. |
Batch Management of Multiple Links | Provide a mechanism to record multiple links in a single text file and launch them collectively as needed. |
Eliminating Platform Dependency & Enhancing Portability | Move away from OS-dependent shortcuts to achieve cross-platform link management using a text-based approach. |
3. Carrying Out the Plan
Installation
Install the PowerShell script “Invoke-Link
(Alias:i
)” as follows:
- Install pwsh-sketches
- Dot-source the function:
. path/to/the/pwsh-sketches/src/Invoke-Link_function.ps1
- Test:
man i
orman Invoke-Link
Execution
Let’s try using “Invoke-Link ”. First, launch a web link in your default browser.
Create a text file named btklab.txt
and add the following two lines:
https://btklab.com
https://github.com/btklab
Execute the links listed in the text file with the following command. By default, only the first link in the file (https://btklab.com ) will open in the default browser.
i btklab.txt
Using the -Doc
option launches the subsequent link (https://github.com/btklab
).
i btklab.txt -Doc
When the -All
(-a
) option is specified, all links in the text file will open in the default browser.
i btklab.txt -All
In addition to web links, you can specify full paths to files or directories. Double quotes around the path are optional. Create a text file named pub-documents.txt
and write the following:
"C:/Users/Public/Documents"
The following command will open the directory specified by the path in File Explorer.
i pub-documents.txt
Applications are launched based on the input type:
- Web links open in the “Default Browser”
- Directories open in “File Explorer”
- Files open with their Default Applications based on file extension
Additionally, if a Windows shortcut file (.lnk
file) is specified as an argument, that shortcut file will be launched. This enables you to mix text file links and Windows shortcut files in your link collection folder, and launch them uniformly using the Invoke-Link
command.
4. Looking Back
The planned requirements have largely been met. The Invoke-Link command is convenient for my daily tasks and has become one of my most frequently used commands.
Challenge | Result | Evaluation |
---|---|---|
Maintaining Quick Launch & Convenience | Applications and files can be launched without leaving the current directory. | ✅ |
Adopting a Text File Format | Link information is managed using a text file, making version control with Git possible | ✅ |
Batch Management of Multiple Links | Multiple links can be recorded in a single text file and launched collectively as needed. | ✅ |
Eliminating Platform Dependency & Enhancing Portability | Combining text files with PowerShell achieves cross-platform operation. | ✅ |
Terms
Here are some technical terms to deepen your understanding of efficiency through the use of links and shortcuts:
- Aliases
-
A mechanism in PowerShell and other shells for assigning short names (aliases) to frequently used commands or scripts. The alias “
i
” was set for this script because it is expected to be typed frequently in everyday use. - Command Line Interface (CLI)
-
A text-based way to interact with a computer. Unlike a Graphical User Interface (GUI), which relies on mouse clicks on icons, the CLI involves typing commands on a keyboard to perform actions such as opening files and running programs. This blog will focus on CLI methods.
- Symbolic Link
-
Windows shortcut files (
.lnk
) are a type of symbolic link. They create a reference (pointer) in the operating system’s file system to a particular file or directory. - Workflow Automation
-
The concept of automating routine manual tasks using scripts or automation tools. By leveraging links, shortcuts, and aliases, operations like launching applications and accessing files are automated and accelerated, directly contributing to overall work efficiency.
- pwsh-sketches – Experimental repository of PowerShell scripts for CLI.
-
Invoke-Link – The PowerShell script that allows you to launch applications from links written in a text file. It’s one of my most frequently used commands within pwsh-sketches .