I am relatively new to applescript, just know basic stuff, need help writing a script.
I have a folder which contains jpg files, they are named pg 1 Jason.jpg, pg1 carol.jpg, pg2 john.jpg, pg2 terry.jpg, pg3 phil.jpg etc.
I want to use applescript to have all pg1 named items as the 1st list in the complete list, all pg2 items as the 2nd list in the complete etc, in the end having 1 list containing many list.
Here’s what I created below
tell application "Finder"
activate
set workFolder to choose folder
set imagesFoder to folder "Images" of workFolder
set allIamges to every item of imagesFoder whose name ends with ".jpg"
set allRtfFiles to every item of workFolder whose name ends with ".rtf"
set uniquePageNumber to {}
set eachPageIamges to {}
set eachImageForOnePage to {}
repeat with a from 1 to (count allIamges)
tell application "Finder"
set captionName to name of item a of allIamges
set spaceNumber to offset of " " in captionName
set pageNumber to (characters 1 thru (spaceNumber - 1) of captionName as string)
if pageNumber is not in uniquePageNumber then
copy pageNumber to end of uniquePageNumber
end if
end tell
end repeat
repeat with b from 1 to (count uniquePageNumber)
set imageName to item b of uniquePageNumber
repeat with i from 1 to (count allIamges)
if name of item i of allIamges starts with imageName then
copy item i of allIamges to end of eachPageIamges
end if
end repeat
end repeat
end tell
set mainList to {}
set firstList to {1, 2, 3}
set secondList to {4, 5, 6, 7}
set end of mainList to firstList
set end of mainList to secondList
return mainList
–-> {{1, 2, 3}, {4, 5, 6, 7}}
set myList to {"pg1 Jammie.jpg", "pg1 carol.jpg", "pg2 John.jpg", "pg2 Phil.jpg", "pg3 Mary.jpg"}
set list1 to {}
set list2 to {}
set list3 to {}
repeat with i in myList
if i begins with "pg1 " then
set end of list1 to contents of i
else if i begins with "pg2 " then
set end of list2 to contents of i
else if i begins with "pg3 " then
set end of list3 to contents of i
end if
end repeat
return {list1, list2, list3}
--> {{"pg1 Jammie.jpg", "pg1 carol.jpg"}, {"pg2 John.jpg", "pg2 Phil.jpg"}, {"pg3 Mary.jpg"}}
set workFolder to choose folder
tell application "Finder"
activate
set imagesFoder to folder "Images" of workFolder
set theImages to every file of imagesFoder whose name ends with ".jpg"
set theRtfFiles to every file of workFolder whose name ends with ".rtf"
set pagesNames to {}
repeat with anImage in theImages
set anImageName to name of anImage
set pageName to text 1 thru 3 of anImageName
if pageName is not in pagesNames then set end of pagesNames to pageName
end repeat
set finalList to {}
repeat with pageName in pagesNames
set pageList to {}
repeat with i from 1 to (count of theImages)
set anImage to item i of theImages
set anImageName to name of anImage
if anImageName begins with pageName then set end of pageList to anImage as alias
end repeat
set end of finalList to pageList
end repeat
end tell
return finalList
---> {{alias "Untitled:Users:123:Desktop:WorkFolder:Images:pg1 .jpg", alias "Untitled:Users:123:Desktop:WorkFolder:Images:pg1 E.jpg", alias "Untitled:Users:123:Desktop:WorkFolder:Images:pg1.jpg"}, {alias "Untitled:Users:123:Desktop:WorkFolder:Images:pg2 40D.jpg", alias "Untitled:Users:123:Desktop:WorkFolder:Images:pg2 DIGITAL_IXUS_400.jpg", alias "Untitled:Users:123:Desktop:WorkFolder:Images:pg2 G.jpg", alias "Untitled:Users:123:Desktop:WorkFolder:Images:pg2 KK.jpg", alias "Untitled:Users:123:Desktop:WorkFolder:Images:pg2_PowerShot_S40.jpg"}, {alias "Untitled:Users:123:Desktop:WorkFolder:Images:pg3 AA.jpg", alias "Untitled:Users:123:Desktop:WorkFolder:Images:pg3 Canon_40D_photoshop_import.jpg", alias "Untitled:Users:123:Desktop:WorkFolder:Images:pg3 F.jpg"}, {alias "Untitled:Users:123:Desktop:WorkFolder:Images:pg4 D.jpg"}}