I’m trying to write a handler that will print readable barcodes in the 128 type B format, but I keep finding my scanner won’t read my printouts, even in large font sizes. The scanner checks out OK with test prints from the font site.
I think I’ve got the code right, but would appreciate anyone with expertise in barcodes to check it, please.
My code is below.
TIA, and good luck with it.
tell application "TextEdit"
activate
tell application "System Events" to tell process "TextEdit"
keystroke "n" using command down
end tell
set theText to "Test of Code128. "
set theTextInsert to ""
set FontSize to 30
set the clipboard to "Font Size is " & FontSize as text
tell application "System Events" to tell process "TextEdit"
keystroke "v" using command down
end tell
tell front document
set the font of last paragraph of its text to "Times"
set the size of last paragraph of its text to 12
end tell
end tell
repeat with y from 0 to 6
set x to y / 2
set theTextInsert to theTextInsert & " " & y as text
set theBarCodeTextModulus to my setUpTextCount(theText & theTextInsert as text)
#
# For barcode128 type B, the start character is 'Ì'
set theBarCodePrintText to ("Ì" & theText & theTextInsert & (ASCII character (theBarCodeTextModulus)) & "Î" as text)
tell application "TextEdit"
activate
set the clipboard to (return & " " & return as text)
tell application "System Events" to tell process "TextEdit"
keystroke "v" using command down
end tell
tell front document
set the font of last paragraph of its text to "Times"
set the size of last paragraph of its text to 6
end tell
delay 0.1
set the clipboard to ("Text Length is " & (count of (theBarCodePrintText as text)) + 2 & return as text)
tell application "System Events" to tell process "TextEdit"
keystroke "v" using command down
end tell
tell front document
set the font of last paragraph of its text to "Times"
set the size of last paragraph of its text to 12
end tell
set the clipboard to (return & " " & return as text)
tell application "System Events" to tell process "TextEdit"
keystroke "v" using command down
end tell
tell front document
set the font of last paragraph of its text to "Times"
set the size of last paragraph of its text to 3
end tell
set the clipboard to (theBarCodePrintText as text)
tell application "System Events" to tell process "TextEdit"
keystroke "v" using command down
end tell
tell front document
set the font of last paragraph of its text to "Code128"
set the size of last paragraph of its text to FontSize
end tell
end tell
end repeat
on setUpTextCount(theText)
set eachCharacterCount to 0
repeat with x from 1 to count of theText
set eachCharacter to item x of theText
set eachCharacterCount to eachCharacterCount + (((ASCII number of eachCharacter) - 32) * x)
end repeat
set eachCharacterCount to eachCharacterCount + 104 # 104 is value of start character of Code 128 type B
set theModulusNumber to eachCharacterCount - (103 * (eachCharacterCount div 103))
# say theModulusNumber
return theModulusNumber
end setUpTextCount