Hi, I am new to mac and I was working with applescript to get files name(in my case it is txt) and creat a new folders with the same name.
here is what I did
tell application “Finder”
repeat with i from 1 to 5
set thename to name of alias “Moussa:Users:aaaa:Desktop:dir”
make new folder at "Moussa:Users:aaaa:Desktop:dir" with properties {name:"thename" & i}
end repeat
end tell
Thanks
Hi, moussa854. Welcome to these fora.
I’m not sure if you’re asking for help or sharing a solution. Here are some comments I hope you’ll find useful.
Your script takes a folder on the desktop and creates five new folders inside it with the name “thename” followed by a number.
The name of alias “Moussa:Users:aaaa:Desktop:dir” will almost always be “dir”, so if you’re hard-coding the folder alias into the script, you could just hard-code the name instead. (However, getting the name of the alias means it will still work if you rename the folder after you’ve compiled the script.)
To make the script work with any folder you choose, you could use ‘choose folder’ or some other method to get the folder into the script.
Since the folder name is the same through all five iterations of the repeat, it would be more efficient to get it before the repeat ” that is, once only.
You’ve used a literal string “thename” to name the new folders. I think you meant to use the variable containing the main folder name, in which case you should leave out the quotes. (ie. thename rather than “thename”.)
set theFolder to (choose folder)
tell application "Finder"
set thename to name of theFolder
repeat with i from 1 to 5
make new folder at theFolder with properties {name:thename & i}
end repeat
end tell
Hi,
do you mean something like this
property dir : "dir"
set dt to path to desktop -- "Moussa:Users:aaaa:Desktop:"
set newDir to (dt as text) & dir -- "Moussa:Users:aaaa:Desktop:dir"
tell application "Finder"
if not (exists folder newDir) then make new folder at dt with properties {name:dir}
repeat with i from 1 to 5
make new folder at newDir with properties {name:dir & i}
end repeat
end tell