Create a new text file in current folder of the current Finder window

touch-bar
keyboard
applescript

#1

This is just an apple script. I assign it to a keyboard shortcut key (ctl-cmd-n) and an touch bar button for Finder. I don't need the right click menu for that anymore

tell application "Finder" to make new file at (the target of the front window) as alias


#2

How did you get a right click menu for this? It seems handy to me


#3

I didn't create a right click menu item, just assigned hot key ctrl-cmd-n to it, like shift-cmd-n for creating new folder.


#4

oh, alright. I’ll try this script out.


#5

BTT already has this function build inside. However it only creates .txt files, but I would like to be able to create .rtf files. Any chance to get this working through btt? Thank you


#6

You can have an empty rtf file as template somewhere and change this script to copy that file as your new rtf


#7

Btw.:

this is the script that BTT uses internally adapted to create rtf files:

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

set fileName to text returned of (display dialog ¬
	"Enter name for new file:" default answer "newfile.rtf")
set absolutePath to POSIX path of currentFolder & fileName
do shell script "shopt -u xpg_echo; echo '{\\rtf1}' > \"" & absolutePath & "\""


#8

Thank you, but its getting too complicated for me here. I will go on copying and pasting my empty .rtf file from the desktop for now. (would be glad anyway to select "create .rtf" fromt the BTT preferences one day). Thanks!


#9

It's not complicated. Just assign that script to any action in BTT using the predefined action "Run Apple Script (blocking)"

One note: it won't work correctly while the BTT window is open.


#10

Ok I will do! I am just afraid that the script could change somethin in my system. Could you explain whats happening in the background?