How to create a blank RTF file in AppleScript inside current folder

applescript

In regards to this question: How to create a blank RTF file in AppleScript?

Can you modify the code in a way it would save the file to the current location of the app? as in instead of saving it to Desktop, it would save it to wherever the .app is located. That way I could add the .app to the Finder-Toolbar and be able to click it from any folder and create that blank rtf file inside the current folder whatever it may be.

if not possible, then maybe force it to ask for saving-location just like it asks for name.

Thanks

Best Answer

If you want to use the code in that linked answer, as is, and modify it to do exactly what it's presently doing with the exception of creating the RTF file at the location the Finder window is set to, via the .app added to the Toolbar in Finder, then change the following line of code:

Change:

set theCustomRichTextFilePathname to ((path to desktop) & customFilename & ".rtf") as string

To:

tell application "Finder"
    set theCustomRichTextFilePathname to ((folder of the front window as string) & customFilename & ".rtf") as string
end tell

Then save it as an AppleScript .app, not .scpt, and drag and drop it onto the Toolbar in Finder.

While that technically answers your question, nonetheless there's probably other code that may/will need to be modified, but that gets you started.