advertisement
Forums

The Forum is sponsored by 
 

AAPL stock: Click Here

You are currently viewing the Tips and Deals forum
Is there a way to take a RTF or TXT file and turn the lines into Folder in the Finder?
Posted by: edgarbc1
Date: November 09, 2011 06:04PM
I have a numbered list of items, roughly 500 lines
1. stuff about kittens
2. stuff about elephants
3. stuff about giraffes
4. stuff about unicorns
etc...
in a rtf file.

I would like to turn the lines in the rtf file into named folders
in the Finder.

Is there a way to do this?
i am no applescript guru, so any pointers would be appreciated.
Ive started this manually and am at folder 37, but i would surmise there
is a way to getting around to doing this by hand...

thanks in advance!!
E
Options:  Reply • Quote
Re: Is there a way to take a RTF or TXT file and turn the lines into Folder in the Finder?
Posted by: Panopticon
Date: November 09, 2011 06:48PM
have you tried Automator.app ?






Options:  Reply • Quote
Re: Is there a way to take a RTF or TXT file and turn the lines into Folder in the Finder?
Posted by: The UnDoug
Date: November 09, 2011 06:48PM
Could certainly be done in the Terminal, but that is probably beyond your comfort zone.



[www.zeemaps.com]
Options:  Reply • Quote
Re: Is there a way to take a RTF or TXT file and turn the lines into Folder in the Finder?
Posted by: edgarbc1
Date: November 09, 2011 07:10PM
Quote
Panopticon
have you tried Automator.app ?

im actually toying with it now and it seems abstract to me..

my programming skills are only in FORTRAN and very little C
do loops are not intuitive in automator as well as extracting a
line based a given character string search...

e.g. search for line with "100.",
select text line with the results of search
input text selection into a variable or parameter for future use
pump variable value into a New Folder action using the value as the name
repeat until 500. is reached.
Options:  Reply • Quote
Re: Is there a way to take a RTF or TXT file and turn the lines into Folder in the Finder?
Posted by: edgarbc1
Date: November 09, 2011 07:16PM
Quote
The UnDoug
Could certainly be done in the Terminal, but that is probably beyond your comfort zone.

i do know some unix
but i dont know how to do a do loop in terminal commands
that would grep a line from a text file and pump it into a mkdir command...
its been so long since ive grepped a string or line im not quite sure
how to do it...
and the do loop aspect of it is also unknown for me

e.g.
grep "100." listing.txt string | mkdir string
Options:  Reply • Quote
Re: Is there a way to take a RTF or TXT file and turn the lines into Folder in the Finder?
Posted by: edgarbc1
Date: November 09, 2011 07:46PM
in my hour looking into this in Automator,
there is no increment command to
increment a dummy variable... e.g. 001 to 002 to 003 etc..

There is no simple way to grab a line from a document or text file.
there is a find command, but its tied to a find/replace action which
does not work for me.

The best i could do is create a Service which i can use by right click.
I do the following manually...
>select the text i want to be the new folder name
>copy to clipboard Ctrl-C
>run service which pumps the contents of the clipboard into a variable which in turn is the new folder name each time the service is executed...

all in all better than nothing, still saves me time in the long run.
if there is anybody who can give pointers to better this process i would
appreciate it!!

E
Options:  Reply • Quote
Re: Is there a way to take a RTF or TXT file and turn the lines into Folder in the Finder?
Posted by: GGD
Date: November 09, 2011 07:55PM
Maybe skip all the attempts at looping and just create a text file with the 500 mkdir command lines using something like TextWrangler, and then paste it into the terminal window.
Options:  Reply • Quote
Re: Is there a way to take a RTF or TXT file and turn the lines into Folder in the Finder?
Posted by: olnacl
Date: November 09, 2011 08:08PM
If you have Keyboard maestro or something similar…

This macro copies one line at a time from a text file (I used your examples, which did not wrap to a second line), created a new folder, pasted the copied name to the new folder, returned to the text file and selected the next line.
I made a single key press the trigger, so, while it would take 500 key presses, you could accomplish your job in a few minutes.
You could also copy and paste the steps several times so one key press would do numerous folders (I didn't find a "repeat" function but there may be one)
(That Click Mouse 4th step can be removed - too lazy to repost the screen shot)
I tried it a couple ways - selecting just part of the line or all of the line - works easily either way




Edited 1 time(s). Last edit at 11/09/2011 08:11PM by olnacl.
Options:  Reply • Quote
Re: Is there a way to take a RTF or TXT file and turn the lines into Folder in the Finder?
Posted by: TheTominator
Date: November 09, 2011 09:11PM
if your plain text file is called "list_of_items.txt", type the following at the Terminal prompt

cat list_of_items.txt | /usr/bin/perl -e 'while ( <> ){ ($dirName) = /^\s*\d+\.\s*(.*)$/ ;mkdir $dirName;}'



Edited 1 time(s). Last edit at 11/09/2011 09:12PM by TheTominator.
Options:  Reply • Quote
Re: Is there a way to take a RTF or TXT file and turn the lines into Folder in the Finder?
Posted by: rjmacs
Date: November 09, 2011 10:01PM
Quote
TheTominator
if your plain text file is called "list_of_items.txt", type the following at the Terminal prompt

cat list_of_items.txt | /usr/bin/perl -e 'while ( <> ){ ($dirName) = /^\s*\d+\.\s*(.*)$/ ;mkdir $dirName;}'

FWIW, i tried that, and it doesn't seem to have worked. smiling smiley



rj
AKA
Vreemac, Moth of the Future
Options:  Reply • Quote
Re: Is there a way to take a RTF or TXT file and turn the lines into Folder in the Finder?
Posted by: TheTominator
Date: November 09, 2011 10:48PM
Quote
rjmacs
Quote
TheTominator
if your plain text file is called "list_of_items.txt", type the following at the Terminal prompt

cat list_of_items.txt | /usr/bin/perl -e 'while ( <> ){ ($dirName) = /^\s*\d+\.\s*(.*)$/ ;mkdir $dirName;}'

FWIW, i tried that, and it doesn't seem to have worked. smiling smiley

In my tests I used a text file with Unix line endings.
The lines are in the format of
1. directory name
2. directory name
where the initial number and period is required.
The command needs to be executed in the same directory as the text file or you need to include the full path to the text file.
Options:  Reply • Quote
Re: Is there a way to take a RTF or TXT file and turn the lines into Folder in the Finder?
Posted by: Seacrest
Date: November 09, 2011 10:54PM
Quote
TheTominator
Quote
rjmacs
Quote
TheTominator
if your plain text file is called "list_of_items.txt", type the following at the Terminal prompt

cat list_of_items.txt | /usr/bin/perl -e 'while ( <> ){ ($dirName) = /^\s*\d+\.\s*(.*)$/ ;mkdir $dirName;}'

FWIW, i tried that, and it doesn't seem to have worked. smiling smiley

In my tests I used a text file with Unix line endings.
The lines are in the format of
1. directory name
2. directory name
where the initial number and period is required.
The command needs to be executed in the same directory as the text file or you need to include the full path to the text file.

It didn't work for me either.
I altered it to print $dirName, and nothing was echoed until I made a few modifications.

I finally made it create directories.

I am not a perl monk, so I won't post my version, but it involved $_ and chop and =~ and some other digeridoo.





I am not Ryan Seacrest, and I do not approve this message.
Options:  Reply • Quote
Re: Is there a way to take a RTF or TXT file and turn the lines into Folder in the Finder?
Posted by: Marc Anthony
Date: November 10, 2011 08:42AM
This is fairly easy with Applescript. My solution:

set listVar to (read (choose file))'s paragraphs
tell application "Finder" to repeat with aLine in listVar
	try
		make folder with properties {name:aLine}
	end try
end repeat



Le poète doit vivre beaucoup, vivre dans tous les sens. - Verlaine
Options:  Reply • Quote
Re: Is there a way to take a RTF or TXT file and turn the lines into Folder in the Finder?
Posted by: edgarbc1
Date: November 10, 2011 01:26PM
Quote
Marc Anthony
This is fairly easy with Applescript. My solution:

set listVar to (read (choose file))'s paragraphs
tell application "Finder" to repeat with aLine in listVar
	try
		make folder with properties {name:aLine}
	end try
end repeat

bloody awesome!
i need to delve into scripting more when I have the need
this is incredibly powerful and more intuitive to me than
the Automator app.
Options:  Reply • Quote
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 213
Record Number of Users: 186 on February 20, 2020
Record Number of Guests: 5122 on October 03, 2020