Jump to content

Script for Multi-version Verse Lookup


Joe Weaks

Recommended Posts

Hi,

I'm having an issue with AppleScript getting a verse that does not exist in a module. For instance, if I try to get "Gen 1:1" from NA28-T, the command will return a string like this:

 

Quote

ERR-The book Gen  cannot be found.

 

It looks normal, as expected. However, I cannot use something like below in AppleScript (no syntax highlighting option for AppleScript??)

if theResult starts with "ERR" then do something

 

The reason is because in the returned string, each character is followed by "\x00" (converted by Python):

Quote

E\x00R\x00R\x00-\x00T\x00h\x00e\x00 \x00b\x00o\x00o\x00k\x00 \x00\x1c G\x00e\x00n\x00\x1d  \x00c\x00a\x00n\x00n\x00o\x00t\x00 \x00b\x00e\x00 \x00f\x00o\x00u\x00n\x00d\x00.\x00

 

I don't know why Accordance would insert those "\x00" into the returned string.

 

Also, I don't know how to deal with it in AppleScript. 

When I do something like below:

if thisResult does not contain "\\x00" then

It does not work.

 

Any help appreciated.

 

 

Edit: 

It's possible that something else was converted into "\x00" when I pass the result to the SystemClipboard.

I don't know how to convert string into unicode character value and have to pass it to the SystemClipboard and convert it into unicode character value from there.

 

To give one more illustration, when I paste the string into this RegEx test website, I get this result (notice the red dots. They are all "\u0000" = "\x00"):

 

image.thumb.png.c5a64a49784eec44f2dcef81784ca8d7.png

Edited by Martin Z
Link to comment
Share on other sites

I don’t have any AppleScript experience, but the \x00 characters would make sense if you’re getting little endian UTF-16 and interpreting it as UTF-8, MacRoman, etc.

Link to comment
Share on other sites

6 hours ago, jlm said:

I don’t have any AppleScript experience, but the \x00 characters would make sense if you’re getting little endian UTF-16 and interpreting it as UTF-8, MacRoman, etc.

Thanks @jlm. You are probably right. But I have no idea how to handle this issue in AppleScript.

 

This does not work:

if thisResult does not contain "\\x00" then

Replacing "\\x00" with "\\u0000" does not work either.

 

Also, the "ERR-" check below will never return as false, because the invisible unicode character "\\x00" is between "E" and "R"

 

On 10/20/2018 at 7:41 PM, Joe Weaks said:

-- add the result if the module contains theReference

if thisResult does not start with "ERR-" then set textResult to textResult & thisModule & return & thisResult & theDelimiter

 

 

Result from Script Debugger (as you can see, the string is cut off after "E" due to the invisible unicode character):

 

image.png.c4ab1214e8c5e08388dc6222b6c95ebc.png

Link to comment
Share on other sites

I have solved it by using a handler (from developer.apple.com)

 

on decodeCharacterHexString(theCharacters)
    copy theCharacters to {theIdentifyingCharacter, theMultiplierCharacter, theRemainderCharacter}
    set theHexList to "123456789ABCDEF"
    if theMultiplierCharacter is in "ABCDEF" then
        set theMultiplierAmount to offset of theMultiplierCharacter in theHexList
    else
        set theMultiplierAmount to theMultiplierCharacter as integer
    end if
    if theRemainderCharacter is in "ABCDEF" then
        set theRemainderAmount to offset of theRemainderCharacter in theHexList
    else
        set theRemainderAmount to theRemainderCharacter as integer
    end if
    set theASCIINumber to (theMultiplierAmount * 16) + theRemainderAmount
    return (ASCII character theASCIINumber)
end decodeCharacterHexString

 

I can then call it:

if myStr contains (decodeCharacterHexString("%00")) then

 

Edited by Martin Z
Link to comment
Share on other sites

I'm sorry. I was ignorant. The above "decodeCharacterHexString()" handler was deprecated. We should use "Character ID" now.

 

There is a much simpler way to do it:

 

if myStr contains character id 0 then

 

Edited by Martin Z
  • Like 1
Link to comment
Share on other sites

Good job tracking down a solution for you, Martin. 

  • Like 2
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...