Copying clipboard to text file with a keyboard shortcut

Table of Contents

    14 Jan 2023

    Script I was using until now, triggered by keyboard shortcut ca defined in Alfred !apps/alfred:

    set command to "pbpaste > "
    set root_path to "/Users/nic/Dropbox/Atom/"
    set timestamp to (do shell script "date '+%y%m%d-%H%M'%S")
    set file_extension to ".txt"
    set file_path to root_path & timestamp & file_extension
    set full_command to command & root_path & timestamp & file_extension
    do shell script full_command
    tell application "Atom" to open POSIX file file_path

    Now switching to Sublime Text as Atom !apps/atom is sunsetting.

    Just switching app name works eg tell application "Sublime Text" to open POSIX file file_path.

    TODO Need to find a way to get the app to be pushed to the front automatically.