mkdir bash script embedded in Applescript issues

I am trying to create an AppleScript that will create a folder structure in the current active Finder window using mkdir. The mkdir command works as expected when run from the terminal but I am not sure why its not working in the AppleScript.

tell application "Finder"
set the theFilePath to (folder of the front window as alias)
set theFilePath2 to POSIX path of theFilePath
do shell script "#!/bin/bash mkdir -p " & quoted form of theFilePath2 "FTC0000\ Job/{_Brief,Artwork,Dispatch/{Low\ Res,Hi\ Res/},History,Links,Supplied}"
end tell

I have previously made the folder structures in AppleScript but the larger more complex ones (not the example above) take a long to build when running and I think the above solution should be more efficient if made to work.

The AppleScripts are shared with other users in our studio and run from the Script Editor menu bar drop down.

Any help appreciated.

tell application "Finder"
	set fp to (target of the front window as alias)
	set fp2 to POSIX path of fp
end tell
do shell script "mkdir -p " & quoted form of fp2 & "FTC0000\\ Job/{_Brief,Artwork,Dispatch/{Low\\ Res,Hi\\ Res/},History,Links,Supplied}"

A few minor things…

The ‘&’ between ‘fp2’ and the folder arguments is missing.

The backslashes in your FTC string need to be escaped with their own ''.

Move the ‘do shell’ outside the Finder tell block. It does execute but it also generates a needless error. Also, finder windows have a target property which I used.

I’m not too familiar with the subtleties of the shell, but I think that the ‘#!’ isn’t required here (or maybe it even breaks things). This is more akin to running a one-liner in the terminal than a .sh file. Also, ‘do shell’ doesn’t need to be pointed to built-in commands so you can just issue the command directly.

Here is some examples to do what you want…

Thanks for taking the time to look at this for me. Now working as i was hoping.

One observation is the [b][/b] in the string “FTC0000\ Job/{_Brief,Artwork,Dispatch/{Low\ Res,Hi\ Res/},History,Links,Supplied}” was actually intended to escape the space in FTC0000 Job directory.

Adding the extra [b][/b] to escape the [b][/b] makes the string work but the output is FTC0000 Job and not FTC0000\ Job and I am unsure why this is?

I have updated the string to use single quotes around directories with spaces.

tell application "Finder"
	set fp to (target of the front window as alias)
	set fp2 to POSIX path of fp
end tell

do shell script "mkdir -p " & quoted form of fp2 & "'FTC0000 Job'/{_Brief,Artwork,Dispatch/{'Low Res','Hi Res'/},History,Links,Supplied}"

Thanks for steering me in the right direction with this.

p_T. I took your script from post 4 and added back the double backslashes. On my computer–running Catalina with the default zsh shell–the folders created by the script included the backslashes. Mockman’s script didn’t work this way because it lacked the required single quotes. My knowledge in this area is limited, but I believe the single quotes are necessary to prevent the expansion of \ by the shell, so that mkdir sees the two backslashes.

tell application "Finder"
	set fp to (target of the front window as alias)
	set fp2 to POSIX path of fp
end tell

do shell script "mkdir -p " & quoted form of fp2 & "'FTC0000\\ Job'/{_Brief,Artwork,Dispatch/{'Low\\ Res','Hi\\ Res'/},History,Links,Supplied}"

Thanks for fixing that. I guess I was even less familiar with the shell than I imagined. Actually, I didn’t know what to expect from that folder block, as I’ve never used mkdir for that.

The OP’s question has been answered and I thought I would try this with ASObjC.

use framework "Foundation"
use scripting additions

tell application "Finder" to set baseFolder to target of front Finder window as text
set baseFolder to current application's NSString's stringWithString:(POSIX path of baseFolder)
set baseFolder to (baseFolder's stringByAppendingPathComponent:"FTC0000 Job")

set fileManager to current application's NSFileManager's defaultManager()

set theFolders to {"_Brief", "Artwork", "Dispatch/Hi Res", "Dispatch/Low Res", "History", "Links", "Supplied"}
repeat with aFolder in theFolders
	set theFolder to (baseFolder's stringByAppendingPathComponent:aFolder)
	(fileManager's createDirectoryAtPath:theFolder withIntermediateDirectories:true attributes:(missing value) |error|:(missing value))
end repeat

I ran some timing tests and there were no differences between the above script and that written by the OP in post 4. However, this assumes that the foundation framework is already in memory, which would normally be the case for me but not necessarily for the OP.

A backslash can be added to a folder name by using two backslashes as in the following:

set baseFolder to (baseFolder's stringByAppendingPathComponent:"FTC0000\\ Job")