Service: create RTF in selected folder

Put this into an Automator service.
Useful to create a Notes file in a project folder (in Finder, obviously).

on run {input, parameters}
	
	if input = {} then
		tell me to activate
		display dialog "One folder, please." buttons {"OK"} default button "OK"
	else if (count of input) ≠ 1 then
		tell me to activate
		display dialog "One folder, please." buttons {"OK"} default button "OK"
	else
		set theFolder to (item 1 of input) as alias
		do shell script "mdls -name kMDItemContentType " & quoted form of (POSIX path of theFolder) -- language-independent
		if result contains "public.folder" then
			--perform the action
			-- ask for name
			tell me to activate
			display dialog "Geef dit bestand een naam:" default answer "naam"
			set theName to text returned of the result & ".rtf"
			set theFile to (theFolder as text) & theName
			set refNum to open for access file theFile with write permission
			write "{\\rtf1\\ansi\\ansicpg1252\\cocoartf1038\\cocoasubrtf290
{\\fonttbl}
{\\colortbl;\\red255\\green255\\blue255;}
\\paperw11900\\paperh16840\\margl1440\\margr1440\\vieww9000\\viewh8400\\viewkind0
}" to refNum -- header for RTF file
			close refNum
			tell application "Finder" to set extension hidden of (theFile as alias) to true
			tell application "TextEdit"
				activate
				open (theFile as alias)
			end tell
		else
			tell me to activate
			display dialog "One folder, please." buttons {"OK"} default button "OK"
		end if
	end if
	return input
end run

Caveat: don’t tinker with the content of the write command. The file will not be usable when this is changed.
When you want something else, like another default font, you can create a file in TextEdit, and edit it’s settings. Then open in TextWrangler, and copy the header into the write command.
The given header is from a Dutch system, where default paper size is A4 (216*297 mm). The result may look strange on systems with different defaults.

Cool! :slight_smile: Any ideas on making a .scpt file in a folder?

Same recipe, probably. Just try it out.
TextWrangler opens just about anything, I think. .scpt too :slight_smile:

Edit:

Strike that.
A .scpt file is not text with a header, like .rtf.
Anyway, you can create any file by talking to the application in question - if it will listen.

Somehow I posted a version that did not open the created file.
Corrected.

I don’t want to derail this thread, just add that I use NuFile and love it.

http://growlichat.com/NuFile.php

Being able to create other filetypes, especially those related to AS, would be worth having a script to do this.

I just saw the article about that on Lifehacker! I’m going to give it a go

Found this AppleScript lookalike of NuFile, and use that now.