sam_rippon

Q: Applescript help

Hi, I am trying to create a script that allows me to generate a set folder structure on a network volume.

 

I currently have the below script that works great but generates the folder to the desktop.

 

How would I change this to include a dialog box that would allow me to navigate to a specific folder within a network volume?

 

I.e. it would take me to the top level of the volume and allow me to select from the subfolder structure my desired location for the folders to generate.

 

Any help would be much appreciated.

 

Thanks

 

Sam

 

global jobNum

 

set ThePath to path to desktop -- the location to make the folder structure

set textYear to text -2 through -1 of ((current date)'s year as text)

set jobNum to text returned of (display dialog "Please enter Job Number:" default answer {textYear & "xxx"})

set JobName to text returned of (display dialog "Please enter Job Name:" default answer "Job Name")

set JobNumName to jobNum & "_" & JobName

 

makeFolderStructure out of {JobNumName, {jobNum & "_" & "AW_Elements", {jobNum & "_" & "AW_Downloads", jobNum & "_" & "AW_Approvals", jobNum & "_" & "AW_Links", {"eps-tiff", "jpg", "psd", "ai"}, jobNum & "_" & "AW_PDF", {"Hires", "Lores"}, jobNum & "_" & "AW_Photography", jobNum & "_" & "AW_Presenters", jobNum & "_" & "AW_Resource", jobNum & "_" & "AW_Gone_to_Print"}, jobNum & "_" & "MG_Elements", {jobNum & "_" & "MG_Downloads", jobNum & "_" & "MG_Renders", {"Lores", "Final"}, jobNum & "_" & "MG_Imports", {"ai", "audio", {"Bought", "Reference"}, "eps-tif", "jpg", "psd", "video"}, jobNum & "_" & "MG_Resource"}, jobNum & "_" & "CR_Elements", {jobNum & "_" & "CR_Presenters", jobNum & "_" & "CR_Downloads", {"Bought", "Reference"}, jobNum & "_" & "CR_Photography", jobNum & "_" & "CR_Resource", jobNum & "_" & "CR_Scamps", jobNum & "_" & "CR_Copy", jobNum & "_" & "CR_Working", {"illustrator", "indesign", "photoshop"}}}} at ThePath

 

to makeFolderStructure out of someItem at someFolder

  set parentFolder to someFolder

  if class of someItem is list then

  repeat with anItem in someItem

  if class of anItem is list then -- add subfolder(s)

  makeFolderStructure out of anItem at someFolder

  else -- add a new child folder at the current parent

  log anItem

  tell application "Finder"

  make new folder at parentFolder with properties {name:anItem}

  set someFolder to the result as alias

  if anItem begins with jobNum & "_AW_" then set label index of someFolder to 6 -- green

  if anItem begins with jobNum & "_CR_" then set label index of someFolder to 3 -- yellow

  if anItem begins with jobNum & "_MG_" then set label index of someFolder to 5 -- purple

  if anItem contains "CR_Presenters" then

  set lanFile to file "XXXXXXX_CR_presenter_STX_VX.indd" of folder "Presenter_Master" of disk "Macintosh HD"

  duplicate {lanFile} to someFolder

  end if

  end tell

  end if

  end repeat

  else -- add a single folder

  tell application "Finder"

  make new folder at someFolder with properties {name:someItem}

  set parentFolder to the result as alias

  if someItem begins with jobNum & "_AW_" then set label index of parentFolder to 6 -- green

  if someItem begins with jobNum & "_CR_" then set label index of parentFolder to 3 -- yellow

  if someItem begins with jobNum & "_MG_" then set label index of parentFolder to 5 -- purple

  end tell

  end if

end makeFolderStructure

 

glo

OS X Mountain Lion (10.8.5)

Posted on Aug 10, 2016 9:50 AM

Close

Q: Applescript help

  • All replies
  • Helpful answers

  • by Niel,Helpful

    Niel Niel Aug 19, 2016 2:11 AM in response to sam_rippon
    Level 10 (311,758 points)
    Aug 19, 2016 2:11 AM in response to sam_rippon

    Replace the second line with:

     

    set ThePath to (choose folder)

     

    (143942)

  • by VikingOSX,Helpful

    VikingOSX VikingOSX Aug 19, 2016 2:11 AM in response to sam_rippon
    Level 7 (20,591 points)
    Mac OS X
    Aug 19, 2016 2:11 AM in response to sam_rippon

    When you first open the Apple Support Community Editor to post, select the blue, Use advanced editor link in the upper right corner of the editor toolbar. This will extend the toolbar to look like this:

    Screen Shot 2016-08-10 at 1.53.23 PM.jpg

     

    Now, you can copy/paste your AppleScript into this editor window, select all of it, and then click Style : Paragraph. This will fix the left truncation of your AppleScript code. The formatting won't be pretty print, but all of the code will be visible.

  • by sam_rippon,Solvedanswer

    sam_rippon sam_rippon Aug 19, 2016 1:15 AM in response to Niel
    Level 1 (4 points)
    Mac OS X
    Aug 19, 2016 1:15 AM in response to Niel

    Thats perfect, thanks Niel