set thisPara to "00000 t"
try
set theNumbers to text 1 thru 5 of thisPara
set theSpace to character 6 of thisPara
set finalLetter to character 7 of thisPara
if (count of thisPara) is not 7 then error "There are not exactly 7 characters in paragraph: " & thisPara
try
theNumbers as integer
on error
error "The first 5 characters are not all numbers in paragraph: " & thisPara
end try
if theSpace is not space then error "Character 6 is not a space in paragraph: " & thisPara
considering case
if finalLetter is not "p" and finalLetter is not "t" then error "Character 7 is not a p or t in paragraph: " & thisPara
end considering
on error theError
display dialog "There was an error:" & return & theError buttons {"OK"} default button 1 with icon stop
end try
set paragraphToTest to "00245 p"
set {tid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {" "}}
set pgraphParts to text items of paragraphToTest
set testResult to false
try
set testResult to (((item 1 of pgraphParts) + 0) = item 1 of pgraphParts as integer)
set testResult to testResult and {"t", "p"} contains (second item of pgraphParts)
end try
set testResult to testResult and (length of paragraphToTest = 7)
if testResult then
display dialog paragraphToTest & " is good."
else
display dialog "no good"
end if
set AppleScript's text item delimiters to tid
Edit: But it gives a false postive to strings like “-2345 p” or “123 p X”. I hope someone comes up with a regular expression solution.
The second solution suited me better
Here’s the script (soo far)
property archivedir : "/Volumes/Archief/DTP/test"
property parentdir : "/Volumes/DTP"
property archivedir_p : "/Volumes/Archief/DTP/test/permanent"
property archivedir_t : "/Volumes/Archief/DTP/test/tijdelijk"
set chosenfile to (choose file)
set filecont to read chosenfile
set archivejobs to paragraphs of filecont
tell application "TextEdit"
activate
close every document saving no
make new document
set the name of window 1 to "Archive Info"
set currentText to text of front document
set newText to currentText & return & "Starting archiving " & (current date) & return
set text of front document to newText
end tell
repeat with archivejob in archivejobs
set {tid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {" "}}
set pgraphParts to text items of archivejob
set testResult to false
try
set testResult to (((item 1 of pgraphParts) + 0) = item 1 of pgraphParts as integer)
set testResult to testResult and {"t", "p"} contains (second item of pgraphParts)
end try
set testResult to testResult and (length of archivejob = 7)
if testResult then
tell application "TextEdit"
set currentText to text of front document
set newText to currentText & return & "Input for Archivejob " & archivejob & " is correct " & (current date)
set text of front document to newText
end tell
set oldDels to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set archivejobNumber to text item 1 of archivejob
set Dest to text item 2 of archivejob
set AppleScript's text item delimiters to oldDels
do shell script ("find " & quoted form of parentdir & " -name " & archivejobNumber & "*" & " -type d -maxdepth 2")
if the result is "" then
tell application "TextEdit"
set currentText to text of front document
set newText to currentText & return & "Jobnumber " & archivejobNumber & " Was not found"
set text of front document to newText
end tell
else
set found to the result
if Dest contains "p" then
do shell script "mv " & quoted form of found & " " & archivedir_p
do shell script ("find " & quoted form of archivedir_p & " -name " & archivejobNumber & "*")
if the result is not "" then
tell application "TextEdit"
set currentText to text of front document
set newText to currentText & return & found & " was copied to " & archivedir_p
set text of front document to newText
end tell
end if
do shell script ("find " & quoted form of parentdir & " -name " & archivejobNumber & "*" & " -type d -maxdepth 2")
if the result is not "" then
set failedarchive to the result
tell application "TextEdit"
set currentText to text of front document
set newText to currentText & return & failedarchive & " was not removed after copying to " & archivedir_p
set text of front document to newText
end tell
end if
end if
end if
if Dest contains "t" then
do shell script "mv " & quoted form of found & " " & archivedir_t
do shell script ("find " & quoted form of archivedir_t & " -name " & archivejobNumber & "*")
if the result is not "" then
tell application "TextEdit"
set currentText to text of front document
set newText to currentText & return & found & " was copied to " & archivedir_t
set text of front document to newText
end tell
end if
do shell script ("find " & quoted form of parentdir & " -name " & archivejobNumber & "*" & " -type d -maxdepth 2")
if the result is not "" then
set failedarchive to the result
tell application "TextEdit"
set currentText to text of front document
set newText to currentText & return & failedarchive & " was not removed after copying to " & archivedir_t
set text of front document to newText
end tell
end if
end if
else
tell application "TextEdit"
set currentText to text of front document
set newText to currentText & return & "Input for Archivejob " & archivejob & " is not correct " & " [INVALID INPUT] " & (current date) & return
set text of front document to newText
end tell
end if
set AppleScript's text item delimiters to tid
end repeat
tell application "TextEdit"
set currentText to text of front document
set newText to currentText & return & return & "Finished archiving " & (current date)
set text of front document to newText
end tell