In this applescript, you can select an app in your Finder window which will create a new Textedit file into the folder that is open in your front Finder window. It will use Terminal to copy a Textedit file from a specific directory that you specify to your front Finder window. In this script, I have the Textedit file in a folder called dont_delete in my home folder.
When you run this script for the first time need to set up the Textedit file and need to change "username" to your home folder name. Save this script as an app in Script Editor and drag the app to a shortcut slot in the Finder window.
tell application "Finder" to set myname to POSIX path of (target of window 1 as alias)
delay 0.5
set x to random number from 1 to 100000
set x1 to x as string
set file_2 to myname & "new_file" & x1 & ".rtf"
tell application "Terminal"
set theTab to selected tab in first window
do script "cp /Users/username/dont_delete/new_file.rtf " & quoted form of file_2 & ";echo \"created new_file in Finder\""
activate
end tell
How does this script work?
tell application "Finder" to set myname to POSIX path of (target of window 1 as alias)
--get the path
delay 0.5
set x to random number from 1 to 100000
--make a random number
set x1 to x as string
--convert the random number to a string
set file_2 to myname & "new_file" & x1 & ".rtf"
--concatenate variables
tell application "Terminal"
--use Terminal to make the file
set theTab to selected tab in first window
--copy the file to the folder that is open in the front Finder window
do script "cp /Users/username/dont_delete/new_file.rtf " & quoted form of file_2 & ";echo \"created new_file in Finder\""
activate
end tell
Resources:
*Looked up how to make a random number. *Looked up how to make a string from an integer because mixing an integer and string you return an array *Looked up how to concatenate variables https://stackoverflow.com/questions/7210188/concatenate-a-string-and-a-variable-into-a-string-in-applescript
*Have this script, because couldn't create new document with Textedit and save onto disk.. https://discussions.apple.com/thread/545324