Move Folder to Newly Created Folder

My applescript creates a new job folder and lets me specify the location. I would like to display a dialog at the end that asks if the user would like to move a folder from another location to this newly created folder. If yes, then the user would be prompted to choose the folder, in either case, yes or no, the newly created folder would be displayed.

Any help would be appreciated.

Thanks,
Josh

set jobNum to text returned of (display dialog "Enter a job number:" default answer "")
set jobName to text returned of (display dialog "Enter a job name:" default answer "")
set jobCity to text returned of (display dialog "Enter job City:" default answer "")
set folderpath to POSIX path of (choose folder with prompt "Select client folder")
set myPath to do shell script "/bin/mkdir -p " & quoted form of folderpath & "/" & quoted form of (jobNum & ", " & jobName & ", " & jobCity) & "/{'Contract Docs'/{CO,Insurance,Prelien,'Price Schedule'},/Billing/,/PM/{Piece,Plans,Sequence,Schedule,Trusses,'BMC Walls',Material}}"
set question to display dialog "Do you need to move an Estimate Folder?" buttons {"Yes", "No"} default button 1
set answer to button returned of question

if answer is equal to "Yes" then
	(if yes then I want to choose a file and have it moved to the newly created parent folder above, then have finder to display the newly created folder)
end if

if answer is equal to "No" then
	(If not then I want finder to display the newly created folder above)
end if

Hello Josh.

This should do what you intended to, but you want to test it properly. Especially your do shell script, which I have reworked a little bit. ( You may wish to take that line from here, and test it in your original script.)

(*

My applescript creates a new job folder and lets me specify the location.  I would like to display a dialog at the end that asks if the user would like to move a folder from another location to this newly created folder. If yes, then the user would be prompted to choose the folder, in either case, yes or no, the newly created folder would be displayed.

*)


set jobNum to text returned of (display dialog "Enter a job number:" default answer "")
set jobName to text returned of (display dialog "Enter a job name:" default answer "")
set jobCity to text returned of (display dialog "Enter job City:" default answer "")
set folderpath to (choose folder with prompt "Select client folder")

try
	
	set myPath to do shell script "/bin/mkdir -p " & quoted form of ((POSIX path of folderpath) & "/" & (jobNum & ", " & jobName & ", " & jobCity)) & "/{'Contract Docs'/{CO,Insurance,Prelien,'Price Schedule'},/Billing/,/PM/{Piece,Plans,Sequence,Schedule,Trusses,'BMC Walls',Material}}"
on error e number n
	tell application (path to frontmost application as text)
		display alert "Something went wrong during creation of client folder structure :
 " & e & " : number : " & n
	end tell
end try
set destPath to ((folderpath as text) & (jobNum & ", " & jobName & ", " & jobCity & ":")) as alias

set question to display dialog "Do you need to move an Estimate Folder?" buttons {"Yes", "No"} default button 1
set answer to button returned of question

if answer is equal to "Yes" then
	--   (if yes then I want to choose a file and have it moved to the newly created parent folder above, then have finder to display the newly created folder)
	
	set estFolder to (choose folder with prompt "Select Estimate folder")
	try
		
		tell application "Finder"
			move estFolder to destPath replacing yes
			reveal folder (name of estFolder) of folderpath
			update destPath
		end tell
	on error e number n
		tell application (path to frontmost application as text)
			display alert "Something went wrong during moving estimates folder:
 " & e & " : number : " & n
		end tell
	end try
else
	--   (If not then I want finder to display the newly created folder above)
	tell application "Finder"
		reveal destPath
		update destPath
	end tell
end if

Thank you!

So it’s almost there. When it moves the estFolder to folderpath, it only moves it to the directory or folder I placed the newly created folder in, not in the newly created folder. I’m not sure how to fix that.

Something else, it behaves a little oddly when choosing the estFolder. When selecting a folder to drill down into, it shows no items in that folder, but if I click a folder from the favorites, or change folder views, then those items will show up, but you have to repeat those steps for every folder you drill down into. Not sure what’s causing that.

Any thoughts?

Josh

Hello.

I have now changed the script, so that the estimates folder is placed inside the folder the user chose to create.
Sometimes, the finder spends some time updating the view in a window, to reflect the reality on the hard drive. That is the only epxlanation I have for the lack of updating.

It works, but there is an error.

Something went wrong during moving estimates folder:
Finder got an error: Can’t get folder “(estFolder)” of folder “" of folder "” of folder “" of folder "” of folder “" of folder "” of folder “***” of startup disk. : number : -1728

Hello.

I now coerce the path to your made folder into an alias. It think that will work a lot better. :slight_smile:

It works, but there is still an error. Odd.

it’s not odd. The error occurs in the line after the move line, because the folder path is not valid.
If you don’t need the folder to be revealed just delete the line

Hello.

I have now made a destPath, which will throw an error if the path doesn’t exist after all.

Hopefully that will work. :slight_smile:

It will not, the moved folder is in folder destpath


 reveal folder (name of estFolder) of folder destPath

StephanK, I removed that line and the error no longer occurs.

McUsrII, I tried the new code you posted but still an error.

I really appreciate the help guys. I still would like to know if there is anyway to get Finder to behave normally when looking up the estFolder. I have to click a folder, switch folder views back and forth to reveal the contents and continue doing that until I reach the estFolder destination. That is consistent.

Thanks again,
Josh

Hello.

Thanks Stefan, that must have been it. I have updated the script. :confused:

I have really no idea why you have to switch back and forth between views, in order to get the folder updated, there may be some latency due to the fact that the folder structure is made with a do shell script however. It may also depend upon how many finder windows you have open.

One idea, that may help, is to command option click on the folder, to force the folder to be “read in”.

maybe the Finder update command could help

Hello.

Thanks Stefan, frankly, I didn’t know, nor suspect there was such a command. I haven’t noticed any difference here, because the files show up immediately, if I have copied something from the terminal window, at least for the moment.

Hopefully the OP notices a difference. :slight_smile: