Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

applescript: create folders using xcel file

Hello,

I am completely in the dark when it comes to Applescript. Ive been pounding the forums all day, and managed to Frankenstein a few scripts together, but cant quite get this script to work.

Ive attached a screen capture of the script, and the excel file its reading from.


Essentially, Im trying to create an Applescript using the excel file i have:

create a heirarchy of folders, using profile (col A) and color names (col C) then copy a couple images (cols F and H) from existing folders (defined in the script), to the newly created color folders (from col C).


Heirarchy like this:

GOLDEN EAGLE (profile: top level folder)

–KINGS CANYON (color: subfolder)

–1634.jpg (image file copied from other local folder)

_1634_skin.jpg (image file copied from other local folder)


Issues not addressed in current script:

Col A, has tons of duplicates...but I only need 1 folder for each profile. (1 GOLDEN EAGLE folder, 1 BEL AIR folder, etc)


Currently when i RUN the script, i get the first folder (GOLDEN EAGLE) but it errors after that.


Ive got a script that creates the folder heirarchy flawlessly. But then i was tasked with copying all these images into each folder. So, im trying to combine them into 1 script.


Please, I really dont want to do this manually, as there are over 1000 images...any help would be greatly appreciated!


User uploaded fileUser uploaded file

MacBook Pro with Retina display, OS X Mavericks (10.9.5)

Posted on May 21, 2015 5:17 PM

Reply
Question marked as Best reply

Posted on May 22, 2015 8:09 AM

Hi,



Because the profileFolder variable contains a string.

Use this in the "application Finder" block --> set profileFolder to folderv1 of myFolder , now the profileFolder variable contains an object (a Finder item)



Try this:

----------------------

set tc to count myData

repeat with x from 2 to tc

tell item x of myData to set {v1, v2, v3, v4} to {item 1, item 3, item 6, item 8}

if v1 = "" or v2 = "" or v3 = "" or v4 = "" then exit repeat

tell application "Finder"

if not (existsfolderv1 of myFolder) then makenewfolderatmyFolderwith properties {name:v1}

set profileF to folder v1 of myFolder

if not (existsfolderv2 of profileF) then makenewfolderatprofileFwith properties {name:v2}

set colorF to folder v2 of profileF

try

--duplicate file v3 of folder "Volumes:KMH BACKUP:Dropbox:EAGLE:" to colorF

end try

try

--duplicate file v4 of folder "Volumes:KMH BACKUP:Dropbox:EAGLE:" to colorF

end try

end tell

end repeat

6 replies
Question marked as Best reply

May 22, 2015 8:09 AM in response to KMH

Hi,



Because the profileFolder variable contains a string.

Use this in the "application Finder" block --> set profileFolder to folderv1 of myFolder , now the profileFolder variable contains an object (a Finder item)



Try this:

----------------------

set tc to count myData

repeat with x from 2 to tc

tell item x of myData to set {v1, v2, v3, v4} to {item 1, item 3, item 6, item 8}

if v1 = "" or v2 = "" or v3 = "" or v4 = "" then exit repeat

tell application "Finder"

if not (existsfolderv1 of myFolder) then makenewfolderatmyFolderwith properties {name:v1}

set profileF to folder v1 of myFolder

if not (existsfolderv2 of profileF) then makenewfolderatprofileFwith properties {name:v2}

set colorF to folder v2 of profileF

try

--duplicate file v3 of folder "Volumes:KMH BACKUP:Dropbox:EAGLE:" to colorF

end try

try

--duplicate file v4 of folder "Volumes:KMH BACKUP:Dropbox:EAGLE:" to colorF

end try

end tell

end repeat

May 22, 2015 11:41 AM in response to Jacques Rioux

Jacques!

You are the absolute best! Your script creates the folders flawlessly!

Yet the TRY (collection of images) produced an error. Im thinking it has to do with the path? Maybe i have to have the absolute path starting from the Startup disk?

None the less, thank you so much for your expertise!

Let me know if you can see anything obvious from below.

Heres the error, starting from the folder creation:


tell application "Finder"

exists folder "Bel Air" of alias "Macintosh HD:Users:kevinherr:Desktop:EAGLE-Photo Folders-NEW:"

--> false

make new folder at alias "Macintosh HD:Users:kevinherr:Desktop:EAGLE-Photo Folders-NEW:" with properties {name:"Bel Air"}

--> folder "Bel Air" of folder "EAGLE-Photo Folders-NEW" of folder "Desktop" of folder "kevinherr" of folder "Users" of startup disk

get folder "Bel Air" of alias "Macintosh HD:Users:kevinherr:Desktop:EAGLE-Photo Folders-NEW:"

--> folder "Bel Air" of folder "EAGLE-Photo Folders-NEW" of folder "Desktop" of folder "kevinherr" of folder "Users" of startup disk

exists folder "Arcadia" of folder "Bel Air" of folder "EAGLE-Photo Folders-NEW" of folder "Desktop" of folder "kevinherr" of folder "Users" of startup disk

--> false

make new folder at folder "Bel Air" of folder "EAGLE-Photo Folders-NEW" of folder "Desktop" of folder "kevinherr" of folder "Users" of startup disk with properties {name:"Arcadia"}

--> folder "Arcadia" of folder "Bel Air" of folder "EAGLE-Photo Folders-NEW" of folder "Desktop" of folder "kevinherr" of folder "Users" of startup disk

get folder "Arcadia" of folder "Bel Air" of folder "EAGLE-Photo Folders-NEW" of folder "Desktop" of folder "kevinherr" of folder "Users" of startup disk

--> folder "Arcadia" of folder "Bel Air" of folder "EAGLE-Photo Folders-NEW" of folder "Desktop" of folder "kevinherr" of folder "Users" of startup disk

copy file "4502.jpg" of folder "Volumes:KMH BACKUP:Dropbox:EAGLE:EAGLE_www-FW:EAGLE_images:panels:" to folder "Arcadia" of folder "Bel Air" of folder "EAGLE-Photo Folders-NEW" of folder "Desktop" of folder "kevinherr" of folder "Users" of startup disk

--> error number -1728 from folder "Volumes:KMH BACKUP:Dropbox:EAGLE:EAGLE_www-FW:EAGLE_images:panels:"

copy file "4502_skin.jpg" of folder "Volumes:KMH BACKUP:Dropbox:EAGLE:EAGLE_www-FW:EAGLE_images:panels:" to folder "Arcadia" of folder "Bel Air" of folder "EAGLE-Photo Folders-NEW" of folder "Desktop" of folder "kevinherr" of folder "Users" of startup disk

--> error number -1728 from folder "Volumes:KMH BACKUP:Dropbox:EAGLE:EAGLE_www-FW:EAGLE_images:panels:"

exists folder "Bel Air" of alias "Macintosh HD:Users:kevinherr:Desktop:EAGLE-Photo Folders-NEW:"

--> true

May 22, 2015 5:16 PM in response to KMH

Hi,


KMH wrote:


copy file "4502.jpg" of folder "Volumes:KMH BACKUP:Dropbox:EAGLE:EAGLE_www-FW:EAGLE_images:panels:" to folder "Arcadia" of folder "Bel Air" of folder "EAGLE-Photo Folders-NEW" of folder "Desktop" of folder "kevinherr" of folder "Users" of startup disk

--> error number -1728 from folder "Volumes:KMH BACKUP:Dropbox:EAGLE:EAGLE_www-FW:EAGLE_images:panels:"

copy file "4502_skin.jpg" of folder "Volumes:KMH BACKUP:Dropbox:EAGLE:EAGLE_www-FW:EAGLE_images:panels:" to folder "Arcadia" of folder "Bel Air" of folder "EAGLE-Photo Folders-NEW" of folder "Desktop" of folder "kevinherr" of folder "Users" of startup disk

--> error number -1728 from folder "Volumes:KMH BACKUP:Dropbox:EAGLE:EAGLE_www-FW:EAGLE_images:panels:"


Yes, the issue is the path of the "panels" folder, remove "Volumes:", because HFS path (path with colon character) doesn't need the "Volumes:"


If this does not work :

To get the right path : run this script :

set the clipboard to (choose folderwith prompt "Select the 'panels' folder") as string


Now the path is in the clipboard, paste it in your script

May 22, 2015 5:46 PM in response to Jacques Rioux

Jacques!

That did the trick! Worked perfectly. Just removed VOLUMES from the path.

Thank you again for your amazing skills. I see your name all over this forum...for a very good reason...

Your awesome!


off the record:

Could you recommend a resource for learning AppleScript, for an idiot like me? I don't think there is an 'AppleScript for Dummies' book.

Thanks again!

applescript: create folders using xcel file

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.