Launch-Software "Run Anything from a Plain Text Link"

Launch applications from links written in a text file.

Page content

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

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:

  1. Install pwsh-sketches
  2. Dot-source the function:
    • . path/to/the/pwsh-sketches/src/Invoke-Link_function.ps1
  3. Test:
    • man i or
    • man 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 Invoke-Link command I introduced here was created to streamline my daily tasks. Its main goals can be summarized as follows:

  1. Maintaining quick startup and convenience,
  2. Managing link information using plain text files,
  3. Allowing batch management and launching of multiple links,
  4. And improving portability by eliminating environment dependencies.

All of these objectives have been largely achieved, and Invoke-Link has become one of my frequently used commands.

Objective Result Evaluation
Maintaining quick startup and convenience Able to launch apps and files without changing the current directory
Using plain text files Managing link information with text files enables version control with Git
Batch management of multiple links Multiple links are stored in a single text file and can be launched collectively
Eliminating environment dependencies and improving portability Combination of text files and PowerShell allows cross-platform use

Now, let me explain how I manage link files in my environment. My home directory for shell work is as follows:

C:\Users\btklab
├───cms
│   └───drafts        <-- working directory

Inside the working directory, I created a subdirectory named work to store the link files.

C:\Users\btklab
├───cms
│   └───drafts
│         └───work    <-- link file storage
│              ├─ amazon.txt
│              ├─ bing.txt
│              ├─ chrome.txt
│              ├─ outlook.txt
│              └─ youtube.txt

This folder contains over 200 link files, including website URLs, absolute paths to local files, application executable paths, Windows shortcuts(.lnk), and PowerShell scripts (.ps1). Among them, I usually use about 10 frequently.

Naming Strategy: Prioritizing Thought Flow

A key point when naming link files is to start with “the full name that naturally comes to mind.” For example, for launching the Outlook app, I name the file straightforwardly as outlook.txt.

This allows me to reflect my thought process directly in the command.

i ./work/outlook.txt

There is also the option of using abbreviations like ol.txt, but caution is needed. Using abbreviations changes the thought flow as follows:

  1. Think: “I want to open Outlook.”
  2. Think: “What was the abbreviation again?”
  3. Think: “Oh, it’s ol.”
  4. Then input: i ./work/ol.txt

Although abbreviations reduce typing, they introduce an extra step to recall the abbreviation during the thought process. For me, maintaining the natural flow of thought is far more important than reducing keystrokes.

Importance of Thought-Aligned Command Design

This approach of naming and specifying options according to the user’s thought order is a fundamental design principle not only for Invoke-Link but for all my CLI command design. Instead of memorizing commands, making them intuitive to use reduces stress and improves long-term productivity.

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 .