Help with a script please

Hello,

Someone has kindly given mea script to run to do a few finder actions. However I am a bit stuck now. Step 1 wasn’t working (can’t make the path of htdocsDir into type item) so I did a bit of googling and discovered to POSIX which works fine.

It’s my step 2 which is erroring now

Step 2 error:

Finder got an error: Can't set folder \"ssx\" of folder \"htdocs\" of folder \"xamppfiles\" of folder \"XAMPP\" of folder \"Applications\" of startup disk to contents of folder \"/wordpress\" of file \"Macintosh HD:Users:nicolaelvin:Downloads:wordpress\"." number -10006 from folder "ssx" of folder "htdocs" of folder "xamppfiles" of folder "XAMPP" of folder "Applications" of startup disk

Applescript:


--setup paths:
-- adjust these as necessary
set htdocsDir to POSIX file "/Applications/XAMPP/xamppfiles/htdocs/"
set clientsDir to "/Users/nicolaelvin/Huddersfield Website Design/clients"
set downloadsDir to POSIX file "/Users/nicolaelvin/Downloads/wordpress"
-- get the new website's name:

set siteDialog to display dialog "Enter the website name:" default answer "" buttons {"OK", "Cancel"} default button 1
set theSiteName to text returned of siteDialog

tell application "Finder"
	-- step 1
	set newSiteDir to (make new folder at htdocsDir with properties {name:theSiteName})
	
	--step 2
	duplicate contents of folder "/wordpress" of downloadsDir to newSiteDir
	
	--step 3
	duplicate contents of folder "common_files" of folder htdocsDir to folder "wp-content" of newSiteDir
	
	-- step 4
	set newClientDir to (make new folder at clientsDir with properties {name:theSiteName})
	
	--step 5
	make new folder at newClientDir with properties {name:"design"}
	make new folder at newClientDir with properties {name:"client supplied material"}
	
end tell

Hi,

Try changing it to this:

duplicate every item of folder “wordpress” of downloadsDir to newSiteDir

gl,
kel

Hi Nicola. Welcome to MacScripter.

The line of code at step 2 attempts to duplicate a folder called “/wordpress” in the “wordpress” folder in your “Downloads” folder to the folder created in step 1. (The ‘contents of’ is entirely superflous.) Does “/wordpress” actually exist? Or do you really mean the “wordpress” folder itself? If the latter, the line should look like this:

duplicate downloadsDir to newSiteDir

Step 3 attempts to duplicate a folder to a folder you haven’t created yet, so that line should probably be replaced with these two:

make new folder at newSiteDir with properties {name:"wp-content"}
duplicate folder "common_files" of folder htdocsDir to folder "wp-content" of newSiteDir

Step 4 will require clientsDir to be a POSIX file like the other two.

(1) here the instruction which failed for you behave flawlessly here.
Here is the log report :

tell application “AppleScript Editor”
display dialog “Enter the website name:” default answer “” buttons {“OK”, “Cancel”} default button 1
→ {text returned:“ssx”, button returned:“OK”}
end tell
tell application “Finder”
make new folder at file “Macintosh HD:Applications:XAMPP:xamppfiles:htdocs:” with properties {name:“ssx”}
→ folder “ssx” of folder “htdocs” of folder “xamppfiles” of folder “XAMPP” of folder “Applications” of startup disk
end tell
Résultat :
folder “ssx” of folder “htdocs” of folder “xamppfiles” of folder “XAMPP” of folder “Applications” of startup disk of application “Finder”

My guess is that there is a permissions problem

I discover that kel2 and Nigel Garvey reported point 2
(2) folder “/wordpress” of downloadsDir means absolutely nothing for the Finder
(3) you are trying to duplicate the contents of a folder whose Unix path is “/Users/nicolaelvin/Downloads/wordpress/wordpress”
Is it what you really want to do ?

(4) you define clientsDir as an Unix path which isn’t usable by the Finder in general and particularly your instruction :
set newClientDir to (make new folder at clientsDir with properties {name:theSiteName})

KOENIG Yvan (VALLAURIS, France) dimanche 1 septembre 2013 12:12:02

Thanks for the replies and the welcome people.

“wordpress” does exist. That “/” at the beginning was me troubleshooting. It’s just called “wordpress in the downloads folder” I would like the contents of this wordpress folder to be duplicated into the folder I created in step 1.

EDIT: Oops just realised I had appended the wordpress folder onto my downloadsDir folder…

So to make it clear:

  1. I want to create a new directory named [mychosenname]
  2. copy contents of downloads >wordpress to directory [mychosenname]
  3. Step 2 will have resulted a folder called wp-content…I want to then replace into here the contents of “common_files” which is contained within the htdocs directory

OK. If ‘contents of’ is to have its English meaning rather than its AppleScript one, and the “wordpress” folder is directly in the Downloads folder, the whole script might look something like this:


--setup paths:
-- adjust these as necessary
set htdocsDir to ((path to applications folder as text) & "XAMPP:xamppfiles:htdocs:") as alias
set clientsDir to ((path to home folder as text) & "Huddersfield Website Design:clients:") as alias
set downloadsDir to (path to downloads folder)
-- get the new website's name:

set siteDialog to display dialog "Enter the website name:" default answer "" buttons {"OK", "Cancel"} default button 1
set theSiteName to text returned of siteDialog

tell application "Finder"
	-- step 1
	set newSiteDir to (make new folder at htdocsDir with properties {name:theSiteName})
	
	--step 2
	duplicate every item of folder "wordpress" of downloadsDir to newSiteDir
	
	--step 3
	-- Folder "wp-content" is one of the items duplicated in step 2.
	duplicate every item of folder "common_files" of htdocsDir to folder "wp-content" of newSiteDir
	
	-- step 4
	set newClientDir to (make new folder at clientsDir with properties {name:theSiteName})
	
	--step 5
	make new folder at newClientDir with properties {name:"design"}
	make new folder at newClientDir with properties {name:"client supplied material"}
	
end tell

Not tested, of course, since I don’t have your set-up.

Edit: Realised from Nicola’s later edits that folder “wp-content” in step 3 is one of the duplicated items from step 2. Script adjusted accordingly.

We’re getting there! It copied the content of wordpress into the new directory. It’s errored though when copying contents of common_files, because files and folders already exist with the names being copied. So can it be amended to overwrite any files/folders that already exist?

EDIT: It’s ok, I added with replacing to the end of the line and it works!!

Thank you so much.

I have some more ideas for speeding up this workflow…can I use applescript to create a new database named the siteDialog? I usually do this by visiting localhost/phpmyadmin and using the interface there.

Or maybe I need to set up a php script that applescript access and the php script sets up the database?

AND… (sorry I know I am being demanding)…

the wordpress folder it copies the contents of, that requires me to :

  1. go to my browser and download wordpress from http://wordpress.org/latest.zip
  2. extract zip file using the unarchiver

Can these steps be put into that start of the script? The file name is always the same for wordpress.

So I tried this using

do shell script "curl -L " & "http://wordpress.org/latest.zip" & " -o " & downloadsDir

However I get an error: curl: (6) Could not resolve host: HD:Users:nicolaelvin:Downloads; nodename nor servname provided, or not known" number 6

In a shell script, you do have to use POSIX paths. Also, downloaded data isn’t written to a folder, but to a file in that folder, so the path has to specify the file:

-- set downloadsDir to (path to downloads folder)

do shell script "curl -L " & "http://wordpress.org/latest.zip" & " -o " & quoted form of POSIX path of ((downloadsDir as text) & "latest.zip")