I have tried several different path iterations to get the script below to point directly to a folder and text file (inside the same folder) on my desktop with no success. Every iteration errors out, except when I manually select the folder/file with the two “choose folder/file” prompts below.
set destination to (choose folder with prompt "Where would you like to make the folders?")
set textFile to (choose file with prompt "Select the text file you wish to use")
set folderNames to paragraphs of (read textFile)
repeat with oneName in folderNames
tell application "Finder" to make new folder at destination with properties {name:oneName}
end repeat
The choose file and choose folder commands return aliases, and the following also uses aliases.
set destination to "Macintosh HD:Users:Robert:Desktop:Test Folder:" as alias
set textFile to "Macintosh HD:Users:Robert:Desktop:Test Folder:New Text File.txt" as alias
set folderNames to paragraphs of (read textFile)
repeat with oneName in folderNames
if oneName > "" then
tell application "Finder" to make new folder at destination with properties {name:oneName}
end if
end repeat
The following differs in that it uses file/folder specifiers:
set destination to "Macintosh HD:Users:Robert:Desktop:Test Folder:"
set textFile to "Macintosh HD:Users:Robert:Desktop:Test Folder:New Text File.txt"
set folderNames to paragraphs of (read file textFile)
repeat with oneName in folderNames
if oneName > "" then
tell application "Finder" to make new folder at folder destination with properties {name:oneName}
end if
end repeat
You can use the “path to” command to specify the desktop folder if you prefer:
set destination to (path to desktop as text) & "Test Folder:"
set textFile to (path to desktop as text) & "Test Folder:New Text File.txt"
I tested all of the above on my computer without issue.
Rich S. I tested those scripts before posting and they do work. A few thoughts.
You use both “Test Folder” and “Test_Folder” above, and I assume one contains a typo.
Run the following in Script Editor and see what happens. If this throws an error, then Test Folder doesn’t exist and needs to be created.
(path to desktop as text) & "Test Folder" as alias
The following script includes some additional error correction. Please note that the folder “Test Folder” and the file “Test File.txt” have to exist for this script to work.
try
set destination to ((path to desktop as text) & "Test Folder:") as alias
set textFile to ((path to desktop as text) & "Test Folder:Test File.txt") as alias
on error errorMessage
display alert "The following error was reported" message errorMessage
error number -128
end try
set folderNames to paragraphs of (read textFile)
repeat with oneName in folderNames
if oneName > "" then
try
tell application "Finder" to make new folder at destination with properties {name:oneName}
on error errorMessage
display alert "The following error was reported" message errorMessage
error number -128
end try
end if
end repeat