0

I've followed John for creating a new filetext and have it pop up with a shortcut. https://apple.stackexchange.com/a/129702

But once I hit my shortcut, a window opens for renaming the file, then I'll have to go to desktop to open it. I was wondering if I could add a line in the code to have the file open after renaming it immediately?

 try
  tell application "Finder" to set the this_folder ¬
   to (folder of the front window) as alias
on error -- no open folder windows
  set the this_folder to path to desktop folder as alias
end try

set thefilename to text returned of (display dialog ¬
 "Create file named:" default answer "filename.txt")
set thefullpath to POSIX path of this_folder & thefilename
do shell script "touch \"" & thefullpath & "\""
Sup Go
  • 1
  • Change your do shell script command to: do shell script "touch " & thefullpath's quoted form & "; open -e " & thefullpath's quoted form – user3439894 Mar 02 '20 at 22:38

1 Answers1

1

Here you go that should work for you

try
    tell application "Finder" to set the this_folder ¬
        to (container of the front Finder window) as alias
on error -- no open folder windows
    set the this_folder to path to desktop folder as alias
end try

set thefilename to text returned of (display dialog ¬
    "Create file named:" default answer "filename.txt")

set thefullpath to POSIX path of this_folder & thefilename

do shell script "touch \"" & thefullpath & "\""

set theFile to thefullpath as POSIX file as alias

tell application "TextEdit" to open theFile
wch1zpink
  • 7,571