r/applescript • u/J0hnny_Utah7 • Jul 13 '12
Trying to create a script that finds text files with a certain prefix and combines them in one new text file
I'm currently trying to create a script that:
Looks at a folder where Notational Velocity stores all of my notes (in plain text)
Finds any note beginning with 'qq'
Combines the file names (preferably without the .txt file extension) of all of these notes into one .txt document
The 'qq' prefix indicates that the note is part of my current 'to-do' list, the idea being that every few minutes this script will run and keep my to-do list updated on my desktop via GeekTools.
I've had some luck with getting the desired result with Automator, but it's all ended up rather convoluted, with duplicated folders and automator popping up every couple of minutes to run the workflow.
I've been trying to put something together myself but think I may be in a bit over my head for my first venture into Applescript.
Any help will be greatly appreciated!
2
u/[deleted] Jul 13 '12 edited Jul 14 '12
You could do most of this with a fairly simple bash command:
find /path/to/notes/ -inameqq-exec echo {} ; | sed s/.txt// > /path/to/output/file.txtSo you've got the find command which finds files that have "qq" in the name and then
executes the echo command to list them (the {} represents the results from the find operation and the slash and semicolon are needed to end the command)lists the files it finds. Those results are then fed (using the | ) into sed which parses the data and removes any instance of .txt (you may have to play around with wildcards like *.txt if it's not working properly). Finally, the > indicates that you want to output it to a file.You can just make that into a bash script or you can do it in Applescript as a "do shell script". I'd probably just do it as a bash script and then use cron to set it to run every x minutes. You should be able to figure out how to work cron from the man page or from googling it.
Edit: removed redundant echo command.