Solution that uses a shell script or an Automator workflow
Open Automator and create a workflow. When asked to choose a workflow type, choose one that fits your preference.
Drag the template Utilities » Run Shell Script into the empty workflow; this opens a large text field. Paste the following code into the text field:
#!/bin/bash
EXTENSION=xxx
SCRIPT_NAME='Create a file whose first line determines the file name'
TMP_FILE="$(mktemp -dt "create_file_whose_first_line_determines_file_name.XXXXXXXXXX")/New file whose first line determines the file name.txt"
echo 'untitled.txt' > "${TMP_FILE}" && open -neW "${TMP_FILE}"
TARGET_FILE="$(head -n 1 "${TMP_FILE}").${EXTENSION}"
if tail -n +2 "${TMP_FILE}" >> "${TARGET_FILE}"
then
osascript -e "display notification \"${TARGET_FILE}\" with title \"File created\""
open -R "${TARGET_FILE}"
else
osascript -e "display notification \"${TARGET_FILE}\" with title \"Unable to create file\""
open -R "${TMP_FILE}"
fi
(Note: Change EXTENSION=xxx
to whatever extension you need.)
Save your workflow to any location that is convenient. Run the workflow without arguments; it will open a temporary file in a new TextEdit instance and wait for you to save and close TextEdit. The script will then create the file as per your requirements.
If successful, the script will reveal the newly created file in the Finder.
If the script is unable to create a file, it will reveal the temporary file in the Finder.
I solved (in a way) this by using Spark (app for Mac) I recorded my keyboard keys to select the first line and rename (File > Rename). All with a shortcut. I hope it helps someone else.. – poupou – 2015-06-28T10:01:05.937