Strange behavior in Leopard not occuring in Tiger

Hi everybody, I have a script that I’m using to “ship” PDFs to different newspapers. It reads the comment of the “Get Info” window of the PDF (paragraph 1 is the name of the newspaper and paragraph 2 is publication date) and uses it to find the appropriate record (newspaper name) of a database I created (I’m scripting Database Events). Everything was working as expected in Tiger except for the access speed of the database (about 10 seconds per PDF). So I ran the script to a 10.5.8 Leopard machine and there is no more 10 seconds lag per PDF, speed is great. The only problem with Leopard now is when the script encounters characters such as “é”,“è”, it throws an error “Database Events got an error: Can’t get record “La Liberté” of database “base de donnees journaux”.”. That wasn’t happening in Tiger. So here’s the part of the script that’s problematic. The funny thing about it is if I activate the line "if publication_name is “La Liberté” then set publication_name to “La Liberté”, it works perfectly.

tell application “Finder”
activate
set this_item to (choose file)
set my_container to (get container of this_item) as string
set my_email_folder to my_container & “envoyer par email”
set my_web_folder to my_container & “envoyer par browser Firefox”
set upload_result to “”
set file_name to get name of this_item
set publication_name to paragraph 1 of (get comment of this_item)
–if publication_name is “La Liberté” then set publication_name to “La Liberté”
end tell

–gather database record fields results
tell application “Database Events”
set quit delay to 0
database “/Users/scyr/Documents/Databases/base de donnees journaux.dbev”
tell database “base de donnees journaux”
set liste_des_field to get value of every field of record publication_name
set my_name to item 1 of liste_des_field
set my_format to item 2 of liste_des_field
set my_province to item 3 of liste_des_field
set email_contact to item 4 of liste_des_field
set my_langue to item 5 of liste_des_field
set my_nbcol to item 6 of liste_des_field
set my_nblignes to item 7 of liste_des_field
set my_col_list to item 8 of liste_des_field
set my_fichier to item 9 of liste_des_field
set my_protocole to item 10 of liste_des_field
set liste_ftp_avant to item 11 of liste_des_field
set my_rep to item 12 of liste_des_field
end tell
end tell

This is the code I use to “tag” the PDF with the comment:

tell application “Finder”
activate
set f to (choose file)
set comment of f to “La Liberté”
end tell

One last thing, if I manually go into “Get Info” of the PDF and type in “La Liberté”, it won’t throw the error, it will work.

Thanks for your help.

I’m getting the same behavior in Snow Leopard. If you want to try it for yourself, here are the steps:

1- execute the following script to create a similar database as mine (2 records only):

tell application “Database Events”
set quit delay to 0
make new database with properties {name:“my test database”}
save result
–next line replace “yourusername” by your own username
database “/Users/yourusername/Documents/Databases/my test database.dbev”

end tell

set La_liberte to {nom:“La Liberté”, ville:“”, type:“colonnes et lignes”, province:“MB”, contact:“production@la-liberte.mb.ca”, langue:“F”, nombre_de_colonnes:5, nombre_de_lignes:215, liste_des_colonnes:{2, 4.06, 6.13, 8.19, 10.25}, type_de_fichier:“PDF”, protocole_envoi:“email”, info_ftp:{}, representant:“”}

set The_Gazette to {nom:“The Gazette”, ville:“”, type:“colonnes et lignes”, province:“QC”, contact:“”, langue:“E”, nombre_de_colonnes:10, nombre_de_lignes:292, liste_des_colonnes:{0.9375, 2, 3.0625, 4.125, 5.1875, 6.25, 7.3125, 8.375, “NA”, 10.5}, type_de_fichier:“PDF”, protocole_envoi:“ftp”, info_ftp:{“ftp.gazette.com”, “thegazette”, “gaz”, “thegazette”}, representant:“The Corporation”}

set my_publications to {La_liberte, The_Gazette}

set z to 1
set my_publications_count to count every item in my_publications
repeat my_publications_count times
set this_publication to item z of my_publications
set my_name to nom of this_publication
set my_type to type of this_publication
set my_prov to province of this_publication
set my_lang to langue of this_publication
set my_contact to contact of this_publication
set my_rep to representant of this_publication
set my_nb_col to nombre_de_colonnes of this_publication
set my_nb_lignes to nombre_de_lignes of this_publication
set my_inter_column_list to liste_des_colonnes of this_publication
set this_count to count every item in my_inter_column_list
set my_column_list_string to “”
set counter to 1
set virgule to “,”
repeat this_count times
if counter = this_count then set virgule to “”
set my_column_list_string to my_column_list_string & (item counter of my_inter_column_list) & virgule as string
set counter to counter + 1
end repeat
set my_column_list to my_column_list_string
set my_inter_ftp_list to info_ftp of this_publication
set this_count2 to count every item in my_inter_ftp_list
set my_ftp_list_string to “”
set counter2 to 1
set virgule to “,”
repeat this_count2 times
if counter2 = this_count2 then set virgule to “”
set my_ftp_list_string to my_ftp_list_string & (item counter2 of my_inter_ftp_list) & virgule as string
set counter2 to counter2 + 1
end repeat

set my_ftp_list to my_ftp_list_string
set my_type_fichier to type_de_fichier of this_publication
set my_protocole to protocole_envoi of this_publication

set my_string to “tell application "Database Events"” & return & “tell database "my test database"” & return & “make new record with properties {name:"” & my_name & quote & “}” & return & “tell record” & space & quote & my_name & quote & return & “make new field with properties {name:"type de format", value:” & quote & my_type & quote & “}” & return & “make new field with properties {name:"province", value:” & quote & my_prov & quote & “}” & return & “make new field with properties {name:"contact", value:” & quote & my_contact & quote & “}” & return & “make new field with properties {name:"langue", value:” & quote & my_lang & quote & “}” & return & “make new field with properties {name:"nombre de colonnes", value:” & quote & my_nb_col & quote & “}” & return & “make new field with properties {name:"nombre de lignes", value:” & quote & my_nb_lignes & quote & “}” & return & “make new field with properties {name:"liste des colonnes", value:” & quote & my_column_list & quote & “}” & return & “make new field with properties {name:"type de fichier", value:” & quote & my_type_fichier & quote & “}” & return & “make new field with properties {name:"protocole d’envoi", value:” & quote & my_protocole & quote & “}” & return & “make new field with properties {name:"info ftp", value:” & quote & my_ftp_list & quote & “}” & return & “make new field with properties {name:"representant", value:” & quote & my_rep & quote & “}” & return & “end tell” & return & “save” & return & “end tell” & return & “end tell”
set the clipboard to my_string

tell application “AppleScript Editor”
make new document with properties {contents:my_string, name:“Inter”}
tell document “Inter”
compile
–delay 1
execute
–delay 1
close without saving
end tell
end tell
set z to z + 1
end repeat

-Step 2: execute the following script to set the comment of any file on your computer

tell application “Finder”
activate
set f to (choose file)
set comment of f to “La Liberté”
–if you set comment to “The Gazette” the next script won’t throw any error
end tell

-Step 3 execute the following script and choose the file you just “tagged”

tell application “Finder”
activate
set this_item to (choose file)
set my_container to (get container of this_item) as string
set my_email_folder to my_container & “envoyer par email”
set my_web_folder to my_container & “envoyer par browser Firefox”
set upload_result to “”
set file_name to get name of this_item
set publication_name to paragraph 1 of (get comment of this_item)
–if publication_name is “La Liberté” then set publication_name to “La Liberté”
end tell

–gather database record fields results
tell application “Database Events”
set quit delay to 0
database “/Users/yourusername/Documents/Databases/my test database.dbev”
tell database “my test database”
set liste_des_field to get value of every field of record publication_name
set my_name to item 1 of liste_des_field
set my_format to item 2 of liste_des_field
set my_province to item 3 of liste_des_field
set email_contact to item 4 of liste_des_field
set my_langue to item 5 of liste_des_field
set my_nbcol to item 6 of liste_des_field
set my_nblignes to item 7 of liste_des_field
set my_col_list to item 8 of liste_des_field
set my_fichier to item 9 of liste_des_field
set my_protocole to item 10 of liste_des_field
set liste_ftp_avant to item 11 of liste_des_field
set my_rep to item 12 of liste_des_field
end tell
end tell

You should get an error if you tagged the file with “La Liberté” on step 2 but not if you tagged the file with “The Gazette”. That’s the behavior I’m getting here (Leopard, Snow Leopard). But everything was fine in Tiger…

Browser: Firefox 3.0.6
Operating System: Mac OS X (10.6)

If you created the database in Tiger, you may have not specified “unicode text.” As I understand it, from Leopard forward unicode text is the only form of text used. So you may need to specify that the value from the database be interpreted “as unicode text” before performing the test to see if the two terms are equal.

Even when I rebuild the database in Leopard or Snow Leopard is throws the same error. Anyway, the Database Events dictionnary specifies that values are returned as Unicode Text, so from Unicode comment from the Finder to Unicode Database record name, it should match.

the following line really bugs me though…because it makes it work and I don’t understand why

–if publication_name is “La Liberté” then set publication_name to “La Liberté”

You got me there. Apparently there is a disconnect between the way that value is “equated” in this line versus how it is interpreted in your script. Two things I would try:

  1. Check that there are no extra spaces or return characters in the Comment section of the file’s Get Info window.
  2. Try using “=” instead of “is.” “Is” can often mean “exactly the same” instead of “equal.” If the values are in two different variables, technically they’re “congruent,” not “exactly the same.” Odd distinction, but I’ve seen it work in scripts before, especially when testing string values.

(edit) 3. Try “contains” if neither “=” or “is” work. I’ve also seen that work.

Will try that Kevin. Thank you.