These are just some random notes I jotted down about your script; ponderances on which you may wish to meditate.
The difference between setting a variable (set x to y) and declaring it as a property (property x : “value”) is that the former is done at runtime, during script execution, and the latter sets variables at launch. For some scripts, this is important as a matter of executing properly; for others, this is strictly a matter of efficiency.
For your script, the following variables never change through runs:
target_URL, xPosition, yPosition, width, barcodeSize, barcodeType, fontName, fontSize, hrPosition
The way your script runs currently, each time it takes a pass through, those variables are all set again–to the same values. You might consider declaring them at launch in properties instead: you’ll add a virtually undetectable amount of time to launch, but you won’t be needlessly resetting these variables each time the script body executes.
I’m confused by the ticket type check. If you’re only getting two ticket strings, one beginning with “1” and one beginning with “2”, what exactly does this do:
if bc_number starts with "1" then
set ok_flag to "Y"
else if bc_number starts with "2" then
set ok_flag to "Y"
end if
Unless I’m missing something, you look to see if the string begins with “1”. If it does, you set ok_flag to “Y”; if it doesn’t, you set ok_flag to . . . “Y”. Oversight? Should this set a different value for ok_flag on “2”?
It looks like it might be control of some kind, in the event the page title is not in the proper string form. In that case, you could just do this:
if bc_number starts with "1" or bc_number starts with "2" then
set ok_flag to "Y"
end if
This is very important to note:
Your main control is checking to see if bc_count is 13 characters long, to make sure you’ve got a page with a bar code on it. Here’s another frequently seen window title that also is 13 characters long:
“404 Not Found”
You need a new validation method here. You could check title length and if it begins with “1” or “2”, but that’s still kinda kludgy. You might consider making your successfully generated page titles something like this:
Barcode: 1234567890123
Then replace this code:
set bc_number to name of front window --title of safari window
set bc_count to count bc_number
set ok_flag to "N"
if bc_count is 13 then
With this code:
set page_title to name of front window --title of safari window
set bc_number to (characters 10 through 22 of page_title) as text
set ok_flag to "N"
if page_title begins with "Barcode: " then
I have to go get ready for work, so I must stop here, but I’ll check back later today to see if you have any questions.
Postscript: Aren’t Dymo printers just a BLAST? 