How can I get it to look at my desktop and get a list of all folders on the desktop and then do the info below on a repeat, its important that it also ignores the following folders on the desktop begining with “2_” and “Hot”
Its important that in the same applescript I need to reference each of the folders created as marked and also the brand and week extracted from the Folders on the desktop.
OBVIOUSLY THE FIRST LINE WAS USED TO TEST MY INITIAL SCRIPT, BUT THE FOLDER Diva_WK65_PSD IS THE FORM OF OTHER FOLDERS ON THE DESKTOP
set folderPath to "Hal 9000:Users:matthew:Desktop:Diva_WK65_PSD"
set {oldTID, my text item delimiters} to {my text item delimiters, ":"}
set folderName to last text item of folderPath
set my text item delimiters to "_WK"
set FolderEndName to last text item of folderName
set brandName to first text item of folderName
set my text item delimiters to "_PSD"
set weekNumber to first text item of FolderEndName
set my text item delimiters to oldTID
--set up names to destination folders and create locally
set this_local_folder to "Hal 9000:Users:matthew:Pictures:2011-2012"
set localWeekFolder to my getFolderPath("WK" & weekNumber, this_local_folder)
set localBrandFolder to my getFolderPath(brandName, localWeekFolder)
--Folder below required for reference later
set localBrandFolder_Low_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", localBrandFolder)
--Folder below required for reference later
set localBrandFolder_High_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", localBrandFolder)
--set up names to destination folders and create over Netwrok including an already exisiting folder
set this_Network_folder to "DCKGEN:Brands:Zoom:Brand - Zoom:Upload Photos:2012:"
set networkWeekFolder to my getFolderPath("WK" & weekNumber, this_Network_folder)
set networkBrandFolder to my getFolderPath(brandName, networkWeekFolder)
--Folder below required for reference later
set networkBrandFolder_Low_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", networkBrandFolder)
set website_images to "DCKGEN:Website_Images:"
--set up names to destination folders and create over Netwrok for FTP collection (based on a mounted drive)
set this_ftp_folder to "Impulse:"
set ftpWeekFolder to my getFolderPath("Week" & weekNumber, this_ftp_folder)
set ftpBrandFolder to my getFolderPath(brandName, ftpWeekFolder)
--Folder below required for reference later
set ftpBrandFolder_Low_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", ftpBrandFolder)
--Folder below required for reference later
set ftpBrandFolder_High_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", ftpBrandFolder)
on getFolderPath(tName, folderPath)
tell application "Finder" to tell folder folderPath
if not (exists folder tName) then
return (make new folder at it with properties {name:tName}) as string
else
return (folder tName) as string
end if
end tell
end getFolderPath
To return a list of every folder on your desktop and repeat for every one NOT named beginning with “2_” or “Hot”, the following should do the trick.
set dtF to paragraphs of (do shell script "ls -F ~/Desktop | grep '/' | cut -d'/' -f1")
repeat with i from 1 to number of items in dtF
set this_item to item i of dtF
if this_item does not start with "2_" and this_item does not start with "Hot" then
-- insert actions here
end if
end repeat
I’ve added it to the script but this only pulls out the first folder (starting from Z backwards to A)
I need it to loop the whole the script
set dtF to paragraphs of (do shell script "ls -F ~/Desktop | grep '/' | cut -d'/' -f1")
repeat with i from 1 to number of items in dtF
set this_item to item i of dtF
if this_item does not start with "2_" and this_item does not start with "Hot" then
set folderPath to this_item
set {oldTID, my text item delimiters} to {my text item delimiters, ":"}
set folderName to last text item of folderPath
set my text item delimiters to "_WK"
set FolderEndName to last text item of folderName
set brandName to first text item of folderName
set my text item delimiters to "_PSD"
set weekNumber to first text item of FolderEndName
set my text item delimiters to oldTID
end if
end repeat
--set up names to destination folders and create locally
set this_local_folder to "Hal 9000:Users:matthew:Pictures:2011-2012"
set localWeekFolder to my getFolderPath("WK" & weekNumber, this_local_folder)
set localBrandFolder to my getFolderPath(brandName, localWeekFolder)
set localBrandFolder_Low_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", localBrandFolder)
set localBrandFolder_High_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", localBrandFolder)
--set up names to destination folders and create over Netwrok including an already exisiting folder
set this_Network_folder to "DCKGEN:Brands:Zoom:Brand - Zoom:Upload Photos:2012:"
set networkWeekFolder to my getFolderPath("WK" & weekNumber, this_Network_folder)
set networkBrandFolder to my getFolderPath(brandName, networkWeekFolder)
set networkBrandFolder_Low_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", networkBrandFolder)
set website_images to "DCKGEN:Website_Images:"
--set up names to destination folders and create over Netwrok for FTP collection (based on a mounted drive)
set this_ftp_folder to "Impulse:"
set ftpWeekFolder to my getFolderPath("Week" & weekNumber, this_ftp_folder)
set ftpBrandFolder to my getFolderPath(brandName, ftpWeekFolder)
set ftpBrandFolder_Low_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", ftpBrandFolder)
set ftpBrandFolder_High_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", ftpBrandFolder)
on getFolderPath(tName, folderPath)
tell application "Finder" to tell folder folderPath
if not (exists folder tName) then
return (make new folder at it with properties {name:tName}) as string
else
return (folder tName) as string
end if
end tell
end getFolderPath
I think you have the end repeat in the wrong place!
It’s not that the repeat is getting the first folder (starting from Z backwards to A), rather, it gets every one but is just returning the last one! because you are telling it to get the first folder, set your variables folderPath, folderName, FolderEndName etc, get the next folder, then replace all of the variables it has just set with the new results from the next folder!!
Does this do what you expect?
(Please check through this first and try to work out what will happen as I have not tested this!!)
set dtF to paragraphs of (do shell script "ls -F ~/Desktop | grep '/' | cut -d'/' -f1")
repeat with i from 1 to number of items in dtF
set this_item to item i of dtF
if this_item does not start with "2_" and this_item does not start with "Hot" then
set folderPath to this_item
set {oldTID, my text item delimiters} to {my text item delimiters, ":"}
set folderName to last text item of folderPath
set my text item delimiters to "_WK"
set FolderEndName to last text item of folderName
set brandName to first text item of folderName
set my text item delimiters to "_PSD"
set weekNumber to first text item of FolderEndName
set my text item delimiters to oldTID
end if
--end repeat -- with end repeat here, this will only set the variables above for the very last folder!
--set up names to destination folders and create locally
set this_local_folder to "Hal 9000:Users:matthew:Pictures:2011-2012"
set localWeekFolder to my getFolderPath("WK" & weekNumber, this_local_folder)
set localBrandFolder to my getFolderPath(brandName, localWeekFolder)
set localBrandFolder_Low_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", localBrandFolder)
set localBrandFolder_High_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", localBrandFolder)
--set up names to destination folders and create over Netwrok including an already exisiting folder
set this_Network_folder to "DCKGEN:Brands:Zoom:Brand - Zoom:Upload Photos:2012:"
set networkWeekFolder to my getFolderPath("WK" & weekNumber, this_Network_folder)
set networkBrandFolder to my getFolderPath(brandName, networkWeekFolder)
set networkBrandFolder_Low_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", networkBrandFolder)
set website_images to "DCKGEN:Website_Images:"
--set up names to destination folders and create over Netwrok for FTP collection (based on a mounted drive)
set this_ftp_folder to "Impulse:"
set ftpWeekFolder to my getFolderPath("Week" & weekNumber, this_ftp_folder)
set ftpBrandFolder to my getFolderPath(brandName, ftpWeekFolder)
set ftpBrandFolder_Low_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", ftpBrandFolder)
set ftpBrandFolder_High_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", ftpBrandFolder)
end repeat
on getFolderPath(tName, folderPath)
tell application "Finder" to tell folder folderPath
if not (exists folder tName) then
return (make new folder at it with properties {name:tName}) as string
else
return (folder tName) as string
end if
end tell
end getFolderPath
Every folder name on your desktop (excluding those beginning “2_” & “Hot”) must follow the same naming convention with those elements you intend to use as Delimiters otherwise you will get errors where certain ‘text items’ may not exist!
Of course, you could simply skip any folders that error by adding a try block:-
set dtF to paragraphs of (do shell script "ls -F ~/Desktop | grep '/' | cut -d'/' -f1")
repeat with i from 1 to number of items in dtF
set this_item to item i of dtF
if this_item does not start with "2_" and this_item does not start with "Hot" then
try
set folderPath to this_item
set {oldTID, my text item delimiters} to {my text item delimiters, ":"}
set folderName to last text item of folderPath
set my text item delimiters to "_WK"
set FolderEndName to last text item of folderName
set brandName to first text item of folderName
set my text item delimiters to "_PSD"
set weekNumber to first text item of FolderEndName
set my text item delimiters to oldTID
end try
end if
--end repeat -- with end repeat here, this will only set the variables above for the very last folder!
--set up names to destination folders and create locally
try
set this_local_folder to "Hal 9000:Users:matthew:Pictures:2011-2012"
set localWeekFolder to my getFolderPath("WK" & weekNumber, this_local_folder)
set localBrandFolder to my getFolderPath(brandName, localWeekFolder)
set localBrandFolder_Low_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", localBrandFolder)
set localBrandFolder_High_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", localBrandFolder)
--set up names to destination folders and create over Netwrok including an already exisiting folder
set this_Network_folder to "DCKGEN:Brands:Zoom:Brand - Zoom:Upload Photos:2012:"
set networkWeekFolder to my getFolderPath("WK" & weekNumber, this_Network_folder)
set networkBrandFolder to my getFolderPath(brandName, networkWeekFolder)
set networkBrandFolder_Low_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", networkBrandFolder)
set website_images to "DCKGEN:Website_Images:"
--set up names to destination folders and create over Netwrok for FTP collection (based on a mounted drive)
set this_ftp_folder to "Impulse:"
set ftpWeekFolder to my getFolderPath("Week" & weekNumber, this_ftp_folder)
set ftpBrandFolder to my getFolderPath(brandName, ftpWeekFolder)
set ftpBrandFolder_Low_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", ftpBrandFolder)
set ftpBrandFolder_High_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", ftpBrandFolder)
end try
end repeat
on getFolderPath(tName, folderPath)
tell application "Finder" to tell folder folderPath
if not (exists folder tName) then
return (make new folder at it with properties {name:tName}) as string
else
return (folder tName) as string
end if
end tell
end getFolderPath
Now to the other part, where each folder was created (and those that already existed) how do I set them as varibles?
For example,
set localBrandFolder_High_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_HR", localBrandFolder)
This line was used to create more than one folder as it ran though the folders on the desktop. The next part is I will need to reference them to save files to them.
Is there a way to create variables For example one of the folder names is DIVA_WK30_PSD
On the above line could I set it out to work like this?
set Brand + “_” +(localBrandFolder_Low_Res) to localBrandFolder_Low_Res?