Monday, November 20, 2017
  • Index
  •  » Automator
  •  » Creating subfolders and placing a file in each subfolder

#1 2017-11-05 06:50:19 am

razzle
Member
Registered: 2012-08-14
Posts: 5

Creating subfolders and placing a file in each subfolder

I am having problems putting a file in each subfolders after creating the subfolders. Using automator to creating the subfolders and then using AppleScript to populate the subfolder with a file.

I select the folder in automator then pass this folder in a variable Myfolder over to AppleScript.

Here is the coded I have used below. Any help would be appreciated

Applescript:

on run {input, parameters}
   
    set MyFolder to input as text #set MyFolder to path to current user folder
    display dialog MyFolder
   
    set MyFile to "Macintosh HD:Users:Razzle:Lightroom:Test:_Full Shoot:image.jpg"
   
    display dialog MyFile
   
    tell application "Finder"
   
        set SubFolders to every folder of entire contents of MyFolder
        repeat with aFolder in SubFolders
            display dialog aFolder as string
            duplicate MyFile to aFolder with replacing
        end repeat
    end tell
   
   
   
end run

Offline

 

#2 2017-11-10 08:06:36 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4423

Re: Creating subfolders and placing a file in each subfolder

Hi.

Your script's coercing the input list to text and then trying to get the 'entire contents' of that text. It also tries to duplicate the text to which you've set MyFile to each subfolder, but the Finder seems to understand what's meant in that case. Still, it's better to use a specifier there too.

Applescript:

on run {input, parameters}
   
   set myFolder to item 1 of input -- not 'input as text'.
   display dialog (myFolder as text)
   
   set MyFile to "Macintosh HD:Users:Razzle:Lightroom:Test:_Full Shoot:image.jpg"
   
   display dialog MyFile
   
   tell application "Finder"
       
       set SubFolders to every folder of entire contents of myFolder
       repeat with aFolder in SubFolders
           display dialog aFolder as string
           duplicate file MyFile to aFolder with replacing -- NB. 'file MyFile' to make a file specifier.
       end repeat
   end tell
   
   return input
end run


NG

Offline

 
  • Index
  •  » Automator
  •  » Creating subfolders and placing a file in each subfolder

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)