Hello everyone,
first time poster here. I’ve dabbled in programming for a number of years but I’m definitely no pro!
Using tutotials from this excellent site and my own experience, I’ve managed to put together a little applescript that reads in a particular file from our advertising system and parses out the ad numbers from the file. It then duplicates a PDF file and renames it to the ad system. This is the method we use to get our newspaper advertisements ready.
However, I’m interested in doing the same thing with multiple files, but I just can’t seem to get the code to work with multiple files. I haven’t been able to find any good tutorials (but perhaps I just haven’t been using the right search terms). Anyway, this is what I have so far, and it works OK for my purposes:
(it looks for the term “cust” in the data file, and returns the next 8 characters which are the ad number I need parsed out)
property serialBeginning : “cust”
property serialEnd : ASCII character 22
–Read a chosen file and prepare to search for serialBeginning
set theContents to read (choose file)
set originalDelimiters to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to {serialBeginning}
–Split the file into a list of strings that start with serialBeginning
–Ignore the first item, which is just the text before the first occurence
set theItems to text items 2 thru (count of text items of theContents) of theContents
–trim off excess
set serialArray to {}
repeat with nextItem in theItems
–Add text before serialEnd to serialArray
set serialArray to serialArray & text 1 thru 8 of nextItem
end repeat
–serialArray now contains a list of the serial numbers
set theFolder to choose folder with prompt “Select destination folder” without invisibles
tell application “Finder”
repeat with nextItem in serialArray
duplicate file “Ad Number” of folder theFolder
set the name of file “Ad Number copy” of folder theFolder to nextItem
end repeat
end tell
–set the finalOutput to "Processed ads " and item 1 of serialArray and " to " and the last item of serialArray
display dialog "Processed ads " & item 1 of serialArray & " to " & the last item of serialArray buttons {“OK”} default button 1
My attempts to work with multiple files have all ended up miserably and I haven’t saved any script attempts from them. I’d love a nudge in the right direction, if anyone can help!
Thanks for your time & consideration =)