Hi
I am pretty new to apple scripting I think it would make my job alot easier if I had a script that could take the hours into minute by doing this for me.
OK heres what I have
every month we are archiving files with names like
tcj080103
tcj100203
etc…
I am trying to figure out how to create folder based on the date in the file name, inside a folder named TCJ. I was wanting it to make folders named 080103, 080203 etc inside a folder tcj, and move the files into them with the same date. Do i make any sense, I’m not sure the best way to describe it.
property s_Folder : “start” – path to sourcefolder
property d_folder : “TCJ” – path to destinationfolder
tell application “Finder” to set file_list to every file of folder s_Folder – reads all files in the sourcefolder
repeat with one_file in file_list – repeats with one file from the sourcefolder
tell application “Finder” to set one_file_name to name of (contents of one_file) – get the name of the file
set name_of_folder to items 4 thru 9 of one_file_name as string – get the name for the folder
-- creates a new folder if not exist and move the file in this folder
tell application "Finder"
if not (exists folder name_of_folder of folder d_folder) then
make new folder in folder d_folder with properties {name:name_of_folder}
move file one_file_name of folder s_Folder to folder name_of_folder of folder d_folder with replacing
else
move file one_file_name of folder s_Folder to folder name_of_folder of folder d_folder with replacing
end if
end tell
Hey the script works great, I have one other issue though?
I have many different folders and different file names other than the TCJ folder and files.
When I copy the script and change the prop letter it just sticks the files in random folders Here is what I have
property a_Folder : "Powerbook G3:PDFfiles" --Path To Source Folder
property b_folder : "Powerbook G3:PDFfiles:BHF (Business Hall Of Fame)" --Path to TCJ (Topeka Capital-Journal)
tell application "Finder" to set file_list to every file of folder a_Folder -- reads all files in the sourcefolder
repeat with one_file in file_list -- repeats with one file from the sourcefolder
tell application "Finder" to set one_file_name to name of (contents of one_file) -- get the name of the file
set name_of_folder to items 4 thru 10 of one_file_name as string -- get the name for the folder
-- creates a new folder if not exist and move the file in this folder
tell application "Finder"
if not (exists folder name_of_folder of folder b_folder) then
make new folder in folder b_folder with properties {name:name_of_folder}
move file one_file_name of folder a_Folder to folder name_of_folder of folder b_folder with replacing
else
move file one_file_name of folder a_Folder to folder name_of_folder of folder b_folder with replacing
end if
end tell
end repeat
property s_Folder : "Powerbook G3:PDFfiles" --Path To Source Folder
property d_folder : "Powerbook G3:PDFfiles:TCJ (Topeka Capital-Journal)" --Path to TCJ (Topeka Capital-Journal)
tell application "Finder" to set file_list to every file of folder s_Folder -- reads all files in the sourcefolder
repeat with one_file in file_list -- repeats with one file from the sourcefolder
tell application "Finder" to set one_file_name to name of (contents of one_file) -- get the name of the file
set name_of_folder to items 4 thru 10 of one_file_name as string -- get the name for the folder
-- creates a new folder if not exist and move the file in this folder
tell application "Finder"
if not (exists folder name_of_folder of folder d_folder) then
make new folder in folder d_folder with properties {name:name_of_folder}
move file one_file_name of folder s_Folder to folder name_of_folder of folder d_folder with replacing
else
move file one_file_name of folder s_Folder to folder name_of_folder of folder d_folder with replacing
end if
end tell
end repeat
are all the source files in the same PDFfiles-folder? then this script should work. i hope.
i am relativly new to applescript and have to learning each day.
tell application “Finder” to set file_list to every file of folder a_Folder
repeat with one_file in file_list
tell application “Finder” to set one_file_name to name of (contents of one_file)
set name_of_folder to items 1 thru 3 of one_file_name as string
set name_of_date_folder to items 4 thru 9 of one_file_name as string
-- here you can add all the other foldernames
if name_of_folder contains "bhf" then
set d_folder to "BHF (Business Hall Of Fame)"
end if
if name_of_folder contains "tcj" then
set d_folder to "TCJ (Topeka Capital-Journal)"
end if
tell application "Finder"
if not (exists folder name_of_date_folder of folder d_folder of folder pdf_folder) then
make new folder in folder d_folder of folder pdf_folder with properties {name:name_of_date_folder}
move file one_file_name of folder a_Folder to folder name_of_date_folder of folder d_folder of folder pdf_folder with replacing
else
move file one_file_name of folder a_Folder to folder name_of_date_folder of folder d_folder of folder pdf_folder with replacing
end if
end tell
Ok I have gotten the script how I want it and it works great, just one issue when i run it I get the error finder out of memory please close some applications and try again. This is without anything running but the script. If i pull one folder and a set of files matching that folder over and run it it works fine but when i have all of them it gives this error. Is There something I can do to fix this. Here is what I have and it works this way just not when The folder is full .
property a_Folder : "Aquaman:Desktop Folder:PDFfiles"
property pdf_folder : "Aquaman:Desktop Folder:PDFfiles"
property d_folder : "Aquaman:Desktop Folder:PDFfiles"
tell application "Finder" to set file_list to every file of folder a_Folder
repeat with one_file in file_list
tell application "Finder" to set one_file_name to name of (contents of one_file)
set name_of_folder to items 1 thru 3 of one_file_name as string
set name_of_date_folder to items 4 thru 10 of one_file_name as string
-- here you can add all the other foldernames
if name_of_folder contains "bhf" then
set d_folder to "BHF (Business Hall Of Fame)"
end if
if name_of_folder contains "BOT" then
set d_folder to "BOT (Best of Topeka)"
end if
if name_of_folder contains "CAR" then
set d_folder to "CAR (Race Day)"
end if
if name_of_folder contains "CBB" then
set d_folder to "CBB (College Basketball)"
end if
if name_of_folder contains "COK" then
set d_folder to "COK (Cooking)"
end if
if name_of_folder contains "CPS" then
set d_folder to "Cair-Paravel"
end if
if name_of_folder contains "CRO" then
set d_folder to "CRO (Topeka ScareCrows)"
end if
if name_of_folder contains "CRY" then
set d_folder to "CRY (Counrty Stampede)"
end if
if name_of_folder contains "CUT" then
set d_folder to "CUT (Credit Unions)"
end if
if name_of_folder contains "CZR" then
set d_folder to "CZR (Czars)"
end if
if name_of_folder contains "END" then
set d_folder to "END (End Zone)"
end if
if name_of_folder contains "ESP" then
set d_folder to "ESP (Estate Planning)"
end if
if name_of_folder contains "FAA" then
set d_folder to "FAA (Farm & Auction)"
end if
if name_of_folder contains "FAM" then
set d_folder to "FAM (Family)"
end if
if name_of_folder contains "FIF" then
set d_folder to "FIF (Beyond 50)"
end if
if name_of_folder contains "FLG" then
set d_folder to "FLG (Flower,Lawn & Garden)"
end if
if name_of_folder contains "FRM" then
set d_folder to "FRM (Topeka Farm Show)"
end if
if name_of_folder contains "GAM" then
set d_folder to "GAM (Gifts & More)"
end if
if name_of_folder contains "GLF" then
set d_folder to "GLF (Golf Kansas)"
end if
if name_of_folder contains "HBB" then
set d_folder to "HBB (High School Basketball)"
end if
if name_of_folder contains "HER" then
set d_folder to "HER (Hers Kansas)"
end if
if name_of_folder contains "HHS" then
set d_folder to "HHS (Hayden)"
end if
if name_of_folder contains "HIS" then
set d_folder to "HIS (Hispanic)"
end if
if name_of_folder contains "HOM" then
set d_folder to "HOM (At Home)"
end if
if name_of_folder contains "HPS" then
set d_folder to "HPS (Highland Park)"
end if
if name_of_folder contains "HSF" then
set d_folder to "HSF (High School Football)"
end if
if name_of_folder contains "HSH" then
set d_folder to "HSH (Homw Show)"
end if
if name_of_folder contains "HST" then
set d_folder to "HST (Topeka Home Show)"
end if
if name_of_folder contains "IIT" then
set d_folder to "Invest in Topeka)"
end if
if name_of_folder contains "JOB" then
set d_folder to "JOB (Job Fair)"
end if
if name_of_folder contains "KCG" then
set d_folder to "KCG (Kansas State Campus Guide)"
end if
if name_of_folder contains "KSO" then
set d_folder to "KSO (Kansas Outdoors"
end if
if name_of_folder contains "KSP" then
set d_folder to "KSP (Kansas Plus)"
end if
if name_of_folder contains "LIT" then
set d_folder to "LIT (Life in Topeka)"
end if
if name_of_folder contains "NIE" then
set d_folder to "NIE (Newspapers in Education)"
end if
if name_of_folder contains "NOL" then
set d_folder to "NOL (Northern Light)"
end if
if name_of_folder contains "OLY" then
set d_folder to "OLY (Olympics"
end if
if name_of_folder contains "OVS" then
set d_folder to "OVS (Overland Station)"
end if
if name_of_folder contains "POH" then
set d_folder to "POH (Parade of Homes)"
end if
if name_of_folder contains "PRG" then
set d_folder to "PRG (Progress)"
end if
if name_of_folder contains "RKS" then
set d_folder to "RKS (Rock Kansas)"
end if
if name_of_folder contains "RSM" then
set d_folder to "RSM (Rossville/St. Marys)"
end if
if name_of_folder contains "RTP" then
set d_folder to "RTP & RTR (Road Trips)"
end if
if name_of_folder contains "RTR" then
set d_folder to "RTP & RTR (Road Trips)"
end if
if name_of_folder contains "SAS" then
set d_folder to "SAS (Saturday Saver)"
end if
if name_of_folder contains "SED" then
set d_folder to "SED (Special Edition)"
end if
if name_of_folder contains "SHH" then
set d_folder to "SHH (Shawnee Heights)"
end if
if name_of_folder contains "SLH" then
set d_folder to "SLH (Silver Lake)"
end if
if name_of_folder contains "SPG" then
set d_folder to "SPG (Spring Planting Guide)"
end if
if name_of_folder contains "SRW" then
set d_folder to "SRW (ScareCrows)"
end if
if name_of_folder contains "SSG" then
set d_folder to "SSG (Sunflower State Games)"
end if
if name_of_folder contains "SUN" then
set d_folder to "SUN (Sunflower State Games)"
end if
if name_of_folder contains "SWG" then
set d_folder to "SWG (Severe Weather Guide)"
end if
if name_of_folder contains "SWN" then
set d_folder to "SWN (Southwest Neighbors)"
end if
if name_of_folder contains "tcj" then
set d_folder to "TCJ (Topeka Capital-Journal)"
end if
if name_of_folder contains "TGT" then
set d_folder to "TGT (Target)"
end if
if name_of_folder contains "USO" then
set d_folder to "USO (U.S. Open golf)"
end if
if name_of_folder contains "VOT" then
set d_folder to "VOT (Voter's Guide)"
end if
if name_of_folder contains "WBB" then
set d_folder to "WBB (Washburn basketball)"
end if
if name_of_folder contains "WCG" then
set d_folder to "WCG (Washburn Campus Guide)"
end if
if name_of_folder contains "WEA" then
set d_folder to "WEA (Weather)"
end if
if name_of_folder contains "WED" then
set d_folder to "WED (Weddings)"
end if
if name_of_folder contains "WGU" then
set d_folder to "WGU (Wellness Guide)"
end if
if name_of_folder contains "WIB" then
set d_folder to "WIB (WIBW)"
end if
if name_of_folder contains "WKE" then
set d_folder to "WKE (Weekend)"
end if
if name_of_folder contains "WOT" then
set d_folder to "WOT (Wings Over Topeka)"
end if
tell application "Finder"
if not (exists folder name_of_date_folder of folder d_folder of folder pdf_folder) then
make new folder in folder d_folder of folder pdf_folder with properties {name:name_of_date_folder}
move file one_file_name of folder a_Folder to folder name_of_date_folder of folder d_folder of folder pdf_folder with replacing
else
move file one_file_name of folder a_Folder to folder name_of_date_folder of folder d_folder of folder pdf_folder with replacing
end if
end tell
end repeat
tell application “Finder” to set file_list to every file of folder a_Folder
repeat with one_file in file_list
tell application “Finder” to set one_file_name to name of (contents of one_file)
set object_name to items 1 thru 3 of one_file_name as string
-- here you can add all the object_names wich are different to the first 3 chars of the object_folder
if object_name is "cps" then
set object_name to "Cai"
end if
set name_of_date_folder to items 4 thru 9 of one_file_name as string
tell application "Finder"
set object_folder to name of (every folder of (folder pdf_folder) whose name starts with object_name) as string
if not (exists (folder name_of_date_folder of folder object_folder of folder pdf_folder)) then
make new folder in folder object_folder of folder pdf_folder with properties {name:name_of_date_folder}
move file one_file_name of folder a_Folder to folder name_of_date_folder of folder object_folder of folder pdf_folder with replacing
else
move file one_file_name of folder a_Folder to folder name_of_date_folder of folder object_folder of folder pdf_folder with replacing
end if
end tell