PDA

View Full Version : Please help been stuck on this for a few days now...




Frosty1973
May 17, 2011, 12:08 PM
Hi Im no applescript expert (as you can probably see from below)..
Im trying to get a a user to duplicate a folder and rename it all in the same parent folder.
Each time it works it just replaces the original. I have created this from different scripts I have found.

This is what i have at the moment:

tell application "Finder"
choose folder with prompt "Choose a folder to copy"
set targetFolder to choose folder with prompt "And where do you want it to go?"

set Dialog_1 to display dialog "Enter the Divison Code" default answer "ABCD"
set the DivCode to the text returned of the result
set Dialog_2 to display dialog "Enter the Project Number" default answer "0000"
set the ProjNum to the text returned of the result
set Dialog_3 to display dialog "Enter the Job Number" default answer "0000"
set the JobNum to the text returned of the result
set Dialog_4 to display dialog "Enter the Job Title" default answer "Job Title"
set the JobTitle to the text returned of the result

set name of theFolder to (DivCode & "_" & ProjNum & "_" & JobNum & "_" & JobTitle)
copy theFolder to targetFolder
end tell

Ideally id rather the user didn't have to input the destination folder. I hope this makes some sense, and someone can help..

Thanks Rob



chown33
May 17, 2011, 01:18 PM
First, you haven't defined a variable named theFolder, yet you're trying to use it in the copying. I suspect you need to change the first command sent to Finder to something like:
set theFolder to choose folder with prompt "Choose a folder to copy"


I'm also confused about your use of targetFolder in the copying operation.

Second, I'm pretty copy does not do what you seem to think it does. The copy verb usually refers to the Copy action in an Edit menu, which involves putting a selection into the clipboard. I'm pretty sure the action you want the Finder to perform is called duplicate.

You should consult a reference document on Finder scripting, or open Finder's scripting dictionary in AppleScript Editor and read what it says about the copy and duplicate verbs.

Your current strategy of cobbling pieces together isn't working. The fact that you have a specific goal is causing you to stay focused solely on the goal, rather than taking the time to learn how the parts work, and then direct that knowledge toward the goal. I think you're going to have to choose one of two things:
1. Learn how AppleScript works, and what the correct scripting verbs are for the actions you want done.
2. Have someone else write the entire script for you.

Learning how AppleScript works means you'll learn simple but useful debugging techniques, such as showing a dialog or alert with the contents of a variable, so you can see what theFolder is before trying to use it. Learning to use a real debugger is even better, but good ones aren't free.


You might also look at Automator. It has Finder actions that might be better and easier to setup than writing an entire script yourself from pieces you found on the internet.

Frosty1973
May 18, 2011, 05:41 AM
chown33

Thanks for your advice, I will consider going into greater depths on understanding and learning applescript. I do have some very basic knowledge of automator and applescript.. having created some scripts etc in the past.

But as you say i'm more focussed on the goal..

The script works but as before just duplicates the folder and overwrites the original but with the new information.


tell application "Finder"
set theFolder to choose folder with prompt "Choose a folder to copy"

set Dialog_1 to display dialog "Enter the Divison Code" default answer "ABCD"
set the DivCode to the text returned of the result
set Dialog_2 to display dialog "Enter the Project Number" default answer "0000"
set the ProjNum to the text returned of the result
set Dialog_3 to display dialog "Enter the Job Number" default answer "0000"
set the JobNum to the text returned of the result
set Dialog_4 to display dialog "Enter the Job Title" default answer "Job Title"
set the JobTitle to the text returned of the result

set name of theFolder to (DivCode & "_" & ProjNum & "_" & JobNum & "_" & JobTitle)
set dest to (path to home folder as string)
duplicate theFolder to dest without replacing
end tell

What can i do to stop it replacing the original folder... Thanks