- How To Create A Terminal Script For Os X Download
- How To Create A Terminal Script For Os X 10
- How To Create A Terminal Script For Os X 1
- Movie Terminal Script
Create multiple folders from Terminal | 36 comments | Create New Account
Using Terminal to create macOS usb bootable drive. If there were no important files inside your U SB flash drive, you now can safely plug it to your Mac (or hackintosh) and follow the tutorials below. Go to Application Utilities and Open Terminal app; It’s really important! Make sure the macOS Installer App are in the Application folder. Of course, you can easily create a new Terminal window from the ‘Shell’ menu or by using the ⌘N (or ⌘T) keyboard shortcut. But in some cases, it can be more useful to use a shell command. New windows created with the keyboard shortcut or from the menu will always have the home directory as the current working directory. I'd like to write a script that will run when I log into OS X, which will do the following: 1) Launch Terminal 2) Immediately close the window that Terminal creates when it opens. 3) Preferably, keep Terminal hidden while all this is happening, so all I see is the Terminal icon.
Click here to return to the 'Create multiple folders from Terminal' hint |
The following comments are owned by whoever posted them. This site is not responsible for what they say.
you might find it informative to do 'man xargs'.
xargs is a core unix tool used to accomplish exactly what you are talking about, namely to take a list of data (command arguments) from a file and execute a certain command repeatedly. so in this case, for example, if you had a list of directory names in a file, one per line, you could use xargs to execute the mkdir command once for each line in the file.
xargs is a core unix tool used to accomplish exactly what you are talking about, namely to take a list of data (command arguments) from a file and execute a certain command repeatedly. so in this case, for example, if you had a list of directory names in a file, one per line, you could use xargs to execute the mkdir command once for each line in the file.
You can try this: if you have a list of names of new directories that you want to create--e.g., call it 'list':
cat list | xargs mkdir -vp
xargs will take the lines from its input [the output from cat], combine them into a single line and pass that line as additional arguments to the command specied as xargs' 1st argument--in this case, 'mkdir -vp'. If the resulting line would be too long [there IS an upper limit on the length of your argument string], xargs will invoke the command multiple times with segments of the list that 'fit'.
As kircmc mentioned, be sure that the folder names in the list contain no spaces, or are enclosed in quotes, else you'll get one folder per word on the line.
See the mkdir man page for info on the 'v' and 'p' options. Also, see the xargs man page for more info.
cat list | xargs mkdir -vp
xargs will take the lines from its input [the output from cat], combine them into a single line and pass that line as additional arguments to the command specied as xargs' 1st argument--in this case, 'mkdir -vp'. If the resulting line would be too long [there IS an upper limit on the length of your argument string], xargs will invoke the command multiple times with segments of the list that 'fit'.
As kircmc mentioned, be sure that the folder names in the list contain no spaces, or are enclosed in quotes, else you'll get one folder per word on the line.
See the mkdir man page for info on the 'v' and 'p' options. Also, see the xargs man page for more info.
it is possible to create multiple folders from a list in a file, you will just need to use an additional UNIX command, xargs. for example:
% cat file_names
folder1
folder2
folder3
%cat file_names | xargs -i mkdir {}
% ls | grep folder
folder1
folder2
folder3
%
Note, this was tested on Solaris (don't have access to a mac right now), so the syntax might be slightly different. i'm not sure if the -i is necessary or not. also, i use tcsh, so the backslashes () escape the shell for the curly brackets ({}). depending on what shell you use, you may or may not need these.
% cat file_names
folder1
folder2
folder3
%cat file_names | xargs -i mkdir {}
% ls | grep folder
folder1
folder2
folder3
%
Note, this was tested on Solaris (don't have access to a mac right now), so the syntax might be slightly different. i'm not sure if the -i is necessary or not. also, i use tcsh, so the backslashes () escape the shell for the curly brackets ({}). depending on what shell you use, you may or may not need these.
Another unix method of createing multiple folder is as follows:
% mkdir long_folder_name_{00,01,02,03,04,05,06}
this will creat the seven folders long_folder_name_ and ending in the expansion of the numbers in the array.
% mkdir long_folder_name_{00,01,02,03,04,05,06}
this will creat the seven folders long_folder_name_ and ending in the expansion of the numbers in the array.
Or you can execute
mkdir `cat dirfile`
where dirfile contains the names of the directories. Those are backquotes around the cat command. Most (all?) of the suggestions here require the directory names not to have spaces. The following command creates directory names with spaces. It requires that the directory names are listed in the file 'list', one per line:
awk '{system('mkdir ' $0 '')}' list
Have fun.
Sorry, in the previous post some crucial backslashes vanished as a consequence of the html coding. Here I'll try again:
awk '{system('mkdir ' $0 '')}' list
awk '{system('mkdir ' $0 '')}' list
How To Create A Terminal Script For Os X Download
Ah, but what if they have Double Quotes or Single Quotes in their names? How would one deal with that?
To not care about spaces, quotes, etc, and the name of dirs is in folders.txt:
and _that's_ why I love perl.
perl, perl, what a nightmare. !!!! You should use and the utf8 accented etc chars are not welcome :(
There's no need for the chomp if you use the lowercase L switch. There's no need for the parens, semicolon, or redirection either.
I was referring to the first perl command, when I said it did nothing for me, but I'll add that the second perl command also did nothing. If I just run 'perl' on the command line, I see a process in Activity Monitor, so it's not that I lack perl.
So far, the only commands in this thread that have worked for me are those of the original post, and then the xargs suggestion immediately following.
---
--
osxpounder
So far, the only commands in this thread that have worked for me are those of the original post, and then the xargs suggestion immediately following.
---
--
osxpounder
Then something's fishy: I made a text file 'dirnames.txt' in my home directory with the contents
one
two
three
and then executed the above command in the same directory:
perl -ne 'chomp($x=$_); mkdir($x);' < dirnames.txt
Bingo: three folders, appropriately named.
Cheers,
Paul
one
two
three
and then executed the above command in the same directory:
perl -ne 'chomp($x=$_); mkdir($x);' < dirnames.txt
Bingo: three folders, appropriately named.
Cheers,
Paul
This one did nothing but gave me an error: 'Wilson Mug-Base.jpg: File name too long' Hmm. Is that because the file name had a space in it? I thought the point of the awk trick was that it would work with items that had spaces in their names.
BTW, that's the last item in the list, the Wilson photo.
---
--
osxpounder
BTW, that's the last item in the list, the Wilson photo.
---
--
osxpounder
The 'for' command is very nice for this:
for item in `cat your_list.txt`; do mkdir /path/to/location/$item; done
No text reformatting required.
-systemsboy
The 'for' command is very nice for this: for item in `cat your_list.txt`; do mkdir /path/to/location/$item; done
No text reformatting required.
-systemsboy
for item in `cat your_list.txt`; do mkdir /path/to/location/$item; done
No text reformatting required.
This also fails for me. I get the error:
mkdir: your_list.txt: File exists
---
--
osxpounder
--
osxpounder
Why not jot
I had problems with the spaces.. It was impossible for me to include spaces in the name of the folders with this simple method.. any sugestion?
I had problems with the spaces.. It was impossible for me to include spaces in the name of the folders with this simple method.. any sugestion?
I've always used for this. The sed command converts spaces to backslashed spaces, necessary to 'escape' each space and allow folder names with spaces.
What criteria is used to determine which Unix commands are worthy to be posted as hints here?
Silly me: you don't need the cat. This will do it, too: The for loop and backtick solutions don't work unless the folder names are separated by spaces on one line. Then again, you can't have multiple folders containing spaces that way, and it seems you'd never want to create any such folders.txt file like that anyway.
Here's a way to do it that will create folders even if your list of names have spaces. The file dir_list.txt contains a list of directory names, one per line. Here goes:
That should work for all files, spaces or not.
That should work for all files, spaces or not.
Well, dangit, it didn't work for me. Maybe I goofed, but here's what I did:
Created a plain text document in TextEdit, saved as plain text, UTF-8.
In the same folder, I opened a Terminal, and used pico to create a text file that contained your script. I changed the name of the list.txt file to match mine.
Saved out of pico to a file called 'do'. I chmoded 'do' 0700.
Then I typed:
./do
Nothing happened. No errors, no new folders.
---
--
osxpounder
Created a plain text document in TextEdit, saved as plain text, UTF-8.
In the same folder, I opened a Terminal, and used pico to create a text file that contained your script. I changed the name of the list.txt file to match mine.
Saved out of pico to a file called 'do'. I chmoded 'do' 0700.
Then I typed:
./do
Nothing happened. No errors, no new folders.
---
--
osxpounder
Do is a reserved word in bash. See the reserved words section in the bash man page. If you change the script name to anything else that's not a reserved bash word, it works.
Thanks for the tip. I renamed it to 'herbie', but still, same results -- i.e, none, not even an error message. herbie's contents:
cat list.txt | while read FILE do
mkdir '${FILE}'
done
I'm using bash.
---
--
osxpounder
--
osxpounder
Both uses of 'cat file | ..' in this thread are 'useless use of cat'. Google for that for details. In other words, sloppy coding, time to learn to clean up your messes.
Bob: your kind offer of an Applescript was appreciated. It didn't compile for me, though. It breaks at the $ sign, saying 'Syntax error Expected end of line but found unknown token'.
---
--
osxpounder
---
--
osxpounder
I thought I found a typo or two, so I changed Bob's script a bit, but still no results. I changed the quotes around $dir to single quotes, and that allowed the script to compile, but it did nothing. I saved it as an app and dropped a plain text file, with names, one per line, on it.
I changed 'mdir' to 'mkdir', but that made no difference, either.
---
--
osxpounder
I changed 'mdir' to 'mkdir', but that made no difference, either.
---
--
osxpounder
This is my 3rd attempt at getting this Applescript posted cleanly. First I lost the < because it looked like the start of an html tag. The 2nd time I lost the 's and messed up the mkdir spelling. This time I'm just going to use Plain Old Text, and the heck with indentation and hope that line wrapping doesn't happen
-- AppleScript wrapper to execute UNIX shell scripts with a drag and drop interface.
-- Found basic script at http://MacOSXHints.com
-- Modified to Create directories from a list stored one per line in a file dropped on the script
-- script should handle spaces in name, apostrophes in names, etc..
-- Bob Harris 25-Apr-2006
on open filelist
repeat with afile in filelist
do shell script 'while read DIR;do mkdir -p '$DIR';done <' & quoted form of POSIX path of afile
end repeat
end open
So as long as we're all posting various ways to do this, here is one that: -- AppleScript wrapper to execute UNIX shell scripts with a drag and drop interface.
-- Found basic script at http://MacOSXHints.com
-- Modified to Create directories from a list stored one per line in a file dropped on the script
-- script should handle spaces in name, apostrophes in names, etc..
-- Bob Harris 25-Apr-2006
on open filelist
repeat with afile in filelist
do shell script 'while read DIR;do mkdir -p '$DIR';done <' & quoted form of POSIX path of afile
end repeat
end open
- takes a list of directory (folder) names from a file, one per line
- doesn't require any special escaping (no need for quotes)
- doesn't have any problems with unicode
j.
Ah, just realized you set the encoding in TextEdit when you save. In that case, select 'UTF-8' and just use: Oddly, if you re-open that that file TextEdit, it improperly decodes it as MacRoman. Oh well.
How To Create A Terminal Script For Os X 10
Okay, I win the award for replies to self. :-)
TextEdit -> Preferences -> Open and Save -> Plain text file encoding.
I had both opening/saving set to Automatic. Setting to UTF-8 does the right thing.
j.
TextEdit -> Preferences -> Open and Save -> Plain text file encoding.
I had both opening/saving set to Automatic. Setting to UTF-8 does the right thing.
j.
How To Create A Terminal Script For Os X 1
If you use UTF-8 when saving in TextEdit, this perl invocation will work: :-)
Movie Terminal Script
what, no ruby solution? ;-)