MParker Posted July 27, 2015 Posted July 27, 2015 i'm about to pull my hair out here. i've got an applescript that works perfectly in the applscript editor, but when i try to add it to filemaker as a calculated value, i get that error. i'm not finding what quote i'm missing. any help would be greatly appreciated. this is the script editor version: set afflName to "123456" tell application "Google Chrome" delay 1 tell application "Google Chrome" to set index of window 1 where title contains "Sample Page" to 1 do shell script "open -a Google\\ Chrome" tell active tab of window 1 set t to (execute javascript "document.getElementsByTagName('html')[0].innerHTML") as text if t contains afflName then repeat while loading is true delay 0.1 end repeat set idNumber to text ((offset of afflName in t) - 7) thru ((offset of afflName in t) - 3) of t set strippedNumber to my getNumerals(idNumber) --display alert strippedNumber execute javascript "document.forms['Form1']['ddlAffiliateList'].value = '" & strippedNumber & "'" else display dialog "AFFILIATE NOT FOUND" buttons {"OK"} end if end tell end tell on getNumerals(input) set digits to "1234567890" copy input to nonNumbers repeat with thisnumber in digits set AppleScript's text item delimiters to thisnumber set nonNumbers to every text item of nonNumbers as text end repeat try repeat with thischar in nonNumbers set endTest to item 1 of nonNumbers set AppleScript's text item delimiters to endTest set input to every text item of input set nonNumbers to every text item of nonNumbers set AppleScript's text item delimiters to "" set input to input as text set nonNumbers to nonNumbers as text end repeat end try return input end getNumerals and here is the filemaker version: "set afflName to \"" & $$Affiliate & "\"" & ¶ & "" & ¶ & "tell application \"Google Chrome\"" & ¶ & "delay 1" & ¶ & "tell application \"Google Chrome\" to set index of window 1 where title contains \"Sample Page\" to 1" & ¶ & "do shell script \"open -a Google\ Chrome\"" & ¶ & "tell active tab of window 1" & ¶ & "set t to (execute javascript \"document.getElementsByTagName('html')[0].innerHTML\") as text" & ¶ & "if t contains afflName then" & ¶ & "repeat while loading is true" & ¶ & "delay 0.1" & ¶ & "end repeat" & ¶ & "set idNumber to text ((offset of afflName in t) - 7) thru ((offset of afflName in t) - 3) of t" & ¶ & "set strippedNumber to my getNumerals(idNumber)" & ¶ & "display alert strippedNumber" & ¶ & "execute javascript \"document.forms['Form1']['ddlAffiliateList'].value = '\" & strippedNumber & \"'\"" & ¶ & "else" & ¶ & "display dialog \"AFFILIATE NOT FOUND\" buttons {\"OK\"}" & ¶ & "end if" & ¶ & "end tell " & ¶ & "end tell" & ¶ & "" & ¶ & "on getNumerals(input)" & ¶ & "set digits to \"1234567890\"" & ¶ & "copy input to nonNumbers" & ¶ & "repeat with thisnumber in digits" & ¶ & "set AppleScript's text item delimiters to thisnumber" & ¶ & "set nonNumbers to every text item of nonNumbers as text" & ¶ & "end repeat" & ¶ & "try" & ¶ & "repeat with thischar in nonNumbers" & ¶ & "set endTest to item 1 of nonNumbers" & ¶ & "set AppleScript's text item delimiters to endTest" & ¶ & "set input to every text item of input" & ¶ & "set nonNumbers to every text item of nonNumbers" & ¶ & "set AppleScript's text item delimiters to \"\"" & ¶ & "set input to input as text" & ¶ & "set nonNumbers to nonNumbers as text" & ¶ & "end repeat" & ¶ & "end try" & ¶ & "return input" & ¶ & "end getNumerals" I have to think it's on the "execute javascript \"document.forms['Form1']['ddlAffiliateList'].value = '\" & strippedNumber & \"'\"" & ¶ &" line, but i've tried everything and can't seem to figure it out. please help!
MParker Posted July 27, 2015 Author Posted July 27, 2015 ok, scratch that. it's on the line. "do shell script \"open -a Google\\ Chrome\"" & ¶ & i started a new script and just added one line at a time until it errored out and that's the one. so.....hmmmm.... ok, found it. i guess it needed 3 "\" instead of two between Google and Chrome. weird.
dwdata Posted July 27, 2015 Posted July 27, 2015 "tell application \"Google Chrome\"¶¶ delay 1¶¶ tell application \"Google Chrome\" to set index of window 1 where title contains \"Sample Page\" to 1¶¶ do shell script \"open -a Google\\\ Chrome\"¶¶ tell active tab of window 1¶¶ set t to (execute javascript \"document.getElementsByTagName('html')[0].innerHTML\") as text¶¶ if t contains afflName then¶¶ repeat while loading is true¶¶ delay 0.1¶¶ end repeat¶¶ set idNumber to text ((offset of afflName in t) - 7) thru ((offset of afflName in t) - 3) of t¶¶ set strippedNumber to my getNumerals(idNumber)¶¶ --display alert strippedNumber¶¶ execute javascript \"document.forms['Form1']['ddlAffiliateList'].value = '\" & strippedNumber & \"'\"¶¶ else¶¶ display dialog \"AFFILIATE NOT FOUND\" buttons {\"OK\"}¶¶ end if¶¶ end tell¶¶ end tell¶¶ on getNumerals(input)¶¶ set digits to \"1234567890\"¶¶ copy input to nonNumbers¶¶ repeat with thisnumber in digits¶¶ set AppleScript's text item delimiters to thisnumber¶¶ set nonNumbers to every text item of nonNumbers as text¶¶ end repeat¶¶ try¶¶ repeat with thischar in nonNumbers¶¶ set endTest to item 1 of nonNumbers¶¶ set AppleScript's text item delimiters to endTest¶¶ set input to every text item of input¶¶ set nonNumbers to every text item of nonNumbers¶¶ set AppleScript's text item delimiters to \"\"¶¶ set input to input as text¶¶ set nonNumbers to nonNumbers as text¶¶ end repeat¶¶ end try¶¶ return input¶¶ end getNumerals" 1
comment Posted July 27, 2015 Posted July 27, 2015 i'm about to pull my hair out here. Filemaker has two convenient functions that can be very helpful here: Quote() and Evaluate(). If you paste your original code into a text field, you can then use Quote ( MyField ) to escape it. For example, if the field contains: do shell script "open -a Google\\ Chrome" the result will be: "do shell script \"open -a Google\\\ Chrome\"" Conversely, you can use the Evaluate() function to unescape the text and return the original.
MParker Posted July 27, 2015 Author Posted July 27, 2015 Filemaker has two convenient functions that can be very helpful here: Quote() and Evaluate(). If you paste your original code into a text field, you can then use Quote ( MyField ) to escape it. For example, if the field contains: do shell script "open -a Google\\ Chrome" the result will be: "do shell script \"open -a Google\\\ Chrome\"" Conversely, you can use the Evaluate() function to unescape the text and return the original. that works great, but when i do it, it comes out looking like this: "set afflName to \"123456\"¶tell application \"Google Chrome\"¶delay 1¶ tell application \"Google Chrome\" to set index of window 1 where title contains \"Sample Page\" to 1¶do shell script \"open -a Google\\\ Chrome\"¶ tell active tab of window 1¶ set t to (execute javascript \"document.getElementsByTagName('html')[0].innerHTML\") as text¶ if t contains afflName then¶ repeat while loading is true¶ delay 0.1¶ end repeat¶ set idNumber to text ((offset of afflName in t) - 7) thru ((offset of afflName in t) - 3) of t¶ set strippedNumber to my getNumerals(idNumber)¶ --display alert strippedNumber¶ execute javascript \"document.forms['Form1']['ddlAffiliateList'].value = '\" & strippedNumber & \"'\"¶ else¶ display dialog \"AFFILIATE NOT FOUND\" buttons {\"OK\"}¶ end if¶ end tell¶end tell¶on getNumerals(input)¶ set digits to \"1234567890\"¶ copy input to nonNumbers¶ repeat with thisnumber in digits¶ set AppleScript's text item delimiters to thisnumber¶ set nonNumbers to every text item of nonNumbers as text¶ end repeat¶ try¶ repeat with thischar in nonNumbers¶ set endTest to item 1 of nonNumbers¶ set AppleScript's text item delimiters to endTest¶ set input to every text item of input¶ set nonNumbers to every text item of nonNumbers¶ set AppleScript's text item delimiters to \"\"¶ set input to input as text¶ set nonNumbers to nonNumbers as text¶ end repeat¶ end try¶ return input¶end getNumerals" is there no way to have it show the new lines properly? if i had to go back and edit this later, it would be a nightmare to sift through.
comment Posted July 27, 2015 Posted July 27, 2015 is there no way to have it show the new lines properly? if i had to go back and edit this later, it would be a nightmare to sift through. Actually, it is possible, if you do: Substitute ( Quote ( MyField ) ; "\¶" ; "\¶¶" ) But my point is that you should not try and edit escaped code at all. Instead, unescape it using the Evaluate() function, edit it, then escape it again using the Quote() function. 1
Recommended Posts
This topic is 3404 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now