I am trying to write a script witch has to create a folder plus subfolders in predefined way (user input)
I already have the script for creating folders but I want it to through a dialog like this:
display dialog "Destinatio" buttons {"Desktop", "Cust1", "Cust"} default button 1
set the button_pressed to the button returned of the result
if the button_pressed is "Desktop" then
-- action for 1st button goes here
set DeskTopFolder to (choose folder)
else if the button_pressed is "" then
-- action for 2nd button goes here
else
-- action for 3rd button goes here
end if
This example has 3 destinations I need 5. {“Desktop”, “Cust1”, “Cust2”, “Cust3”, “Cust4”}
The Desktop is no problem but buttons "Cust1-4 have to redirect me to a directory on a mounted Volume let’s say Volumes:DTP:Cust1:Jobs
This would be the main directory for creating the folder and subfolders
How do I get this path in my script?
btw, here’s the script for creating Folders:
-- Set common desktop path
display dialog "Please choose the Client Folder on the Server"
set DeskTopFolder to (choose folder)
-- User enters Job Number and Desciption
set JobNumber to "What is the Job Number?"
set JobDescription to "What is the Job Description?"
set tempNumber to display dialog JobNumber default answer ""
set JobNumberEntered to text returned of tempNumber
set tempDescription to display dialog JobDescription default answer ""
set JobDescriptionEntered to text returned of tempDescription
-- tell finder to create parent folder and sub folders
tell application "Finder"
set parentFolder to make new folder at DeskTopFolder with properties {name:JobNumberEntered & " " & JobDescriptionEntered}
make new folder at parentFolder with properties {name:JobNumberEntered & " VECTOR_files"}
set rasterFolder to make new folder at parentFolder with properties {name:JobNumberEntered & " RASTER_files"}
make new folder at parentFolder with properties {name:JobNumberEntered & " PDF_files"}
make new folder at parentFolder with properties {name:JobNumberEntered & " SUPPORT_files"}
make new folder at parentFolder with properties {name:JobNumberEntered & " PSD_files"}
make new folder at rasterFolder with properties {name:"HI RES"}
make new folder at rasterFolder with properties {name:"LO RES"}
end tell
HI there,
because you can only display 3 buttons in AppleScript maybe it would be a better ideas to choose from list rather than displaying a dialog window e.g.
set user_choice to choose from list {"Desktop", "Cust1", "Cust2", "Cust3", "Cust4"}
tell application "Finder"
if user_choice = "Cust1" then
set Cust1_folder_path to "Volumes:DTP:Cust1:Jobs"
else if user_choice = "Cust2" then
set Cust2_folder_path to "Volumes:DTP:Cust2:Jobs"
else if user_choice = "Cust3" then
set Cust3_folder_path to "Volumes:DTP:Cust3:Jobs"
else if user_choice = "Cust4" then
set Cust3_folder_path to "Volumes:DTP:Cust4:Jobs"
end if
end tell
an alternative to choose more than 3 options is a list
like this
set destFolder to choose from list {"Desktop", "Cust", "Cust2", "Cust3", "Cust4", "Cust5"} with prompt "choose the destinaton folder"
if destFolder is false then return -- user has cancelled
set destFolder to item 1 of destFolder
if destFolder is "Desktop" then
set destFolder to path to desktop
else
set destFolder to ("Volumes:DTP:" & destFolder & ":Jobs:") as alias -- the folder must exist!
end if
Blend:
When running your example nothing happens.
This is what I get in the event Window:
tell current application
choose from list {"Desktop", "Cust1", "Cust2", "Cust3", "Cust4"} with prompt "choose the destinaton folder"
{"Cust1"}
end tell
So it doesn’t really get the path.
Stephan:
When using the Desktop selection I get a message in the event Window:
alias "HD1:Users:administrator:Desktop:"
But when I choose “Cust” I get an error:
Applescript-error File ‘Volumes:DTP:Cust:Jobs’ cannot be found
The Volume is mounted and the Folders do exist
set myPath to (item (character 1 of ((choose from list {"1. Desktop", "2. Docs", "3. Pics", "4. Music", "5. Scripts"}) as string) as number)) of {path to desktop folder, path to documents folder, path to pictures folder, path to music folder, path to scripts folder}
One-liners can be confusing and are usually not faster (though they create fewer variables). Here it is laid out with error checking and conditions, i.e. safer:
set myChoices to {"1. Desktop", "2. Docs", "3. Pics", "4. Music", "5. Scripts"}
set myDestinations to {path to desktop folder, path to documents folder, path to pictures folder, path to music folder, path to scripts folder}
set theChosen to (choose from list myChoices without empty selection allowed and multiple selections allowed) as string
try
set theChoiceNum to character 1 of theChosen as number
on error -- user cancelled
return
end try
set myChosenDestination to item theChoiceNum of myDestinations
That makes it a lot easier to understand, you’re using the number from the myChoices list to reference an item in the myDestinations list.
Thanks for the description
without empty selection allowedandmultiple selections allowed is the default setting, so it can be omitted.
An alternative way of error handling is to check a returned false
set myChoices to {"1. Desktop", "2. Docs", "3. Pics", "4. Music", "5. Scripts"}
set myDestinations to {path to desktop folder, path to documents folder, path to pictures folder, path to music folder, path to scripts folder}
set theChosen to (choose from list myChoices) as string
if theChosen is "false" then return -- false is returned if user cancelled
set theChoiceNum to character 1 of theChosen as number
set myChosenDestination to item theChoiceNum of myDestinations
Thanks for the “without” clarification; I wasn’t sure (though the reply was in the nature of tutorial so more complete than I would normally have used it).
Gentlemen,
Thanks for all the reply’s
But how do I get the path of a Folder on an afp Volume for example ‘DTP:Cust1:Jobs’ while using:
set myChoices to {"1. Desktop", "2. Docs", "3. Pics", "4. Music", "5. Scripts"}
set myDestinations to {path to desktop folder, path to documents folder, path to pictures folder, path to music folder, path to scripts folder}
set theChosen to (choose from list myChoices) as string
if theChosen is "false" then return -- false is returned if user cancelled
set theChoiceNum to character 1 of theChosen as number
set myChosenDestination to item theChoiceNum of myDestinations
And how do I implement the ‘create Folder Script’ shown in my first question?
Hi Peter,
I think you’ve got all the info you need, you’ve just got to call it. Have a look at the script below, it uses all the info you’ve provided and creates the folder structures in the path selected. The myDestinations paths that I have specified are all afp volumes on my system so you should just be able to replace the paths I’ve specified with your own!
set myChoices to {"1. path1", "2. path2", "3. path3", "4. path4", "5. path5"}
set myDestinations to {"PageMakeUpMaster:0-DROP ZONE:", "system_opi1", "approved_eps:BDJO:0-BDJO Internet Text Files", "Digital_Ads:Failure", "Released_Ads:0_lene repeat data"}
set theChosen to (choose from list myChoices) as string
if theChosen is "false" then return -- false is returned if user cancelled
set theChoiceNum to character 1 of theChosen as number as string
set myChosenDestination to item theChoiceNum of myDestinations
make_folders(myChosenDestination, JobNumberEntered, JobDescriptionEntered)
on make_folders(myChosenDestination, JobNumberEntered, JobDescriptionEntered)
tell application "Finder"
set parentFolder to make new folder at myChosenDestination with properties {name:JobNumberEntered & " " & JobDescriptionEntered}
make new folder at parentFolder with properties {name:JobNumberEntered & " VECTOR_files"}
set rasterFolder to make new folder at parentFolder with properties {name:JobNumberEntered & " RASTER_files"}
make new folder at parentFolder with properties {name:JobNumberEntered & " PDF_files"}
make new folder at parentFolder with properties {name:JobNumberEntered & " SUPPORT_files"}
make new folder at parentFolder with properties {name:JobNumberEntered & " PSD_files"}
make new folder at rasterFolder with properties {name:"HI RES"}
make new folder at rasterFolder with properties {name:"LO RES"}
end tell
end make_folders
Thanks again!
Here’s the final script (some text is in Dutch)
One question though: what’s this thing with rasterfolder?
set JobNumber to "Wat is het ordernummer (zie orderbon)?"
set JobDescription to "Wat is de klantnaam (zie orderbon)?"
set tempNumber to display dialog JobNumber default answer ""
set JobNumberEntered to text returned of tempNumber
set tempDescription to display dialog JobDescription default answer ""
set JobDescriptionEntered to text returned of tempDescription
set myChoices to {"1. Desktop", "2. Beursdrukkerij", "3. Leenbakker", "4. Schuitema", "5. Overige"}
set myDestinations to {path to desktop folder, "DTP:Beursdrukkerij:orders", "DTP:Leenbakker:orders", "DTP:Schuitema:orders", "DTP:Overige:orders"}
set theChosen to (choose from list myChoices) as string
if theChosen is "false" then return
set theChoiceNum to character 1 of theChosen as number as string
set myChosenDestination to item theChoiceNum of myDestinations
make_folders(myChosenDestination, JobNumberEntered, JobDescriptionEntered)
on make_folders(myChosenDestination, JobNumberEntered, JobDescriptionEntered)
tell application "Finder"
set parentFolder to make new folder at myChosenDestination with properties {name:JobNumberEntered & "_" & JobDescriptionEntered}
make new folder at parentFolder with properties {name:JobNumberEntered & "_Illustraties"}
make new folder at parentFolder with properties {name:JobNumberEntered & "_Diverse"}
make new folder at parentFolder with properties {name:JobNumberEntered & "_Photoshop"}
make new folder at parentFolder with properties {name:JobNumberEntered & "_Aangeleverd"}
make new folder at parentFolder with properties {name:JobNumberEntered & "_Opmaak"}
make new folder at parentFolder with properties {name:JobNumberEntered & "_Highres"}
make new folder at parentFolder with properties {name:JobNumberEntered & "_Highres_klant"}
make new folder at parentFolder with properties {name:JobNumberEntered & "_Fonts"}
make new folder at parentFolder with properties {name:JobNumberEntered & "_Postscript"}
make new folder at parentFolder with properties {name:JobNumberEntered & "_PDF_certified"}
make new folder at parentFolder with properties {name:JobNumberEntered & "_PDF_scherm"}
make new folder at parentFolder with properties {name:JobNumberEntered & "_Preps"}
open myChosenDestination
end tell
end make_folders