applescript如何删除“\”;在变量中从我的文本中删除

applescript如何删除“\”;在变量中从我的文本中删除,applescript,Applescript,好的,我有一个代码,在我问了一个问题后,从Wolfram alpha获取文本,创建URL并将其存储在变量“answer”中,但是它在文本中混合了/符号,系统因此发音错误。如何从变量中删除所有\符号 tell application "Safari" quit end tell set defaultAnswer to "" set cancelButton to "Cancel" set buttonResearch to "ReSearch" display dialog "Que

好的,我有一个代码,在我问了一个问题后,从Wolfram alpha获取文本,创建URL并将其存储在变量“answer”中,但是它在文本中混合了/符号,系统因此发音错误。如何从变量中删除所有\符号

tell application "Safari"
    quit
end tell

set defaultAnswer to ""
set cancelButton to "Cancel"
set buttonResearch to "ReSearch"

display dialog "Query: " default answer defaultAnswer buttons {cancelButton, buttonResearch} default button buttonResearch cancel button cancelButton with icon 1
copy the result as list to {button_pressed, text_returned}

tell application "Dragon Dictate"
    set listening to false
end tell


if (button_pressed is buttonResearch) and (text_returned is not "") then
    set a to "http://www.wolframalpha.com/input/?i="
    set b to encode_text(text_returned, true, false)
    set c to a & b

    tell application "Safari"
        activate
        open
    end tell
    repeat
        if application "Safari" is running then exit repeat
    end repeat
    delay 1
    tell application "System Events" to tell process "Safari" to set visible to false
    tell application "Safari"
        tell window 1
            set current tab to (make new tab with properties {URL:c})
        end tell
    end tell
end if

say "let me look that up for you now"
delay 6

tell application "Safari" to set theString to (source of document 1)

(* Strip the text and only return the last line*)
set input to do shell script "echo " & (quoted form of theString) & "|sed -n \"/stringified/,/mInput/p\" | sed '$!N;$!D'"



global answer

set offSet1 to "\"stringified\": \""
set offSet2 to "\",\"mInput\""


my strip(offSet1, offSet2, input)

set mywordcount to count of words of answer

if mywordcount is greater than 50 then
    display dialog x
else


end if

tell application "Safari"
    quit
end tell

tell application "Dragon Dictate"
    set listening to true
end tell

on strip(offSet1, offSet2, thedata)
    (* Use the offsets of the pattens to match the text # thru # *)
    set textNumber1 to (offset of offSet1 in thedata)
    set theData1 to text -1 thru (textNumber1 + (count of offSet1)) of thedata
    set textNumber2 to (offset of offSet2 in theData1)
    set textString2 to text from word 1 to (textNumber2 - 1) of theData1
    set thedata to theData1
    set answer to textString2
end strip

-- encoding high-ASCII characters:
on encode_char(this_char)
    set the ASCII_num to (the ASCII number this_char)
    set the hex_list to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
    set x to item ((ASCII_num div 16) + 1) of the hex_list
    set y to item ((ASCII_num mod 16) + 1) of the hex_list
    return ("%" & x & y) as string
end encode_char

-- TEXT ENCODING: encode spaces and high-level ASCII characters (those above 127)
-- encode_URL_A = encode most of the special characters reserved for use by URLs.
on encode_text(this_text, encode_URL_A, encode_URL_B)
    set the standard_characters to "abcdefghijklmnopqrstuvwxyz0123456789"
    set the URL_A_chars to "$+!'/?;&@=#%><{}[]\"~`^\\|*"
    set the URL_B_chars to ".-_:"
    set the acceptable_characters to the standard_characters
    if encode_URL_A is false then set the acceptable_characters to the acceptable_characters & the URL_A_chars
    if encode_URL_B is false then set the acceptable_characters to the acceptable_characters & the URL_B_chars
    set the encoded_text to ""
    repeat with this_char in this_text
        if this_char is in the acceptable_characters then
            set the encoded_text to (the encoded_text & this_char)
        else
            set the encoded_text to (the encoded_text & encode_char(this_char)) as string
        end if
    end repeat
    return the encoded_text
end encode_text
告诉应用程序“Safari”
退出
结束语
将defaultAnswer设置为“”
将取消按钮设置为“取消”
将按钮ReSearch设置为“ReSearch”
显示对话框“查询:”默认回答默认回答按钮{cancelButton,buttonResearch}默认按钮按钮搜索取消按钮取消按钮图标1
将结果作为列表复制到{按下按钮,返回文本}
告诉应用程序“龙口述”
将侦听设置为false
结束语
如果(按下的按钮是buttonResearch)和(返回的文本不是“”),则
将a设置为“http://www.wolframalpha.com/input/?i="
将b设置为编码_文本(返回的文本,true,false)
将c设置为a&b
告诉应用程序“Safari”
激活
打开
结束语
重复
如果应用程序“Safari”正在运行,则退出并重复
结束重复
延迟1
告诉应用程序“系统事件”告诉进程“Safari”将visible设置为false
告诉应用程序“Safari”
告诉窗口1
将当前选项卡设置为(使用属性{URL:c}创建新选项卡)
结束语
结束语
如果结束
说“让我现在帮你查一下”
延迟6
告诉应用程序“Safari”将字符串设置为(文档1的来源)
(*去掉文本,只返回最后一行*)
将输入设置为执行shell脚本“echo”&(字符串的引用形式)&“sed-n\”/stringified/,/mInput/p\“|sed'$!n;$!D'”
全球答案
将偏移量1设置为“字符串化”:“
将偏移量2设置为“\”,“最小输入”
我的条带(偏移量1、偏移量2、输入)
将mywordcount设置为回答字数
如果mywordcount大于50,则
显示对话框x
其他的
如果结束
告诉应用程序“Safari”
退出
结束语
告诉应用程序“龙口述”
将侦听设置为true
结束语
条带上(偏移量1、偏移量2、数据)
(*使用图案的偏移来匹配文本#到#*)
将textNumber1设置为(数据中偏移量1的偏移量)
将数据1设置为数据的文本-1至(文本编号1+(偏移量1计数))
将textNumber2设置为(数据1中偏移量2的偏移量)
将textString2设置为数据1的单词1到(textNumber2-1)之间的文本
将数据设置为数据1
将答案设置为textString2
镶端板条
--编码高ASCII字符:
关于编码字符(此字符)
将ASCII_num设置为(此字符的ASCII编号)
将十六进制列表设置为{“0”、“1”、“2”、“3”、“4”、“5”、“6”、“7”、“8”、“9”、“A”、“B”、“C”、“D”、“E”、“F”}
将x设置为十六进制列表的项目((ASCII_num div 16)+1)
将y设置为十六进制列表的项((ASCII数mod 16)+1)
以字符串形式返回(“%”&x&y)
结束编码字符
--文本编码:对空格和高级ASCII字符(127以上的字符)进行编码
--encode_URL_A=对URL保留使用的大多数特殊字符进行编码。
在encode_text(此_text,encode_URL_A,encode_URL_B)上
将标准字符设置为“abcdefghijklmnopqrstuvwxyz0123456789”

将URL_A_chars设置为“$+!”/?;&@=#%>这里有一个例程,其唯一目的是从字符串中去掉正斜杠

on stripSlash(s)
    set otid to AppleScript's text item delimiters
    try
        set AppleScript's text item delimiters to "\\"
        set s to text items of s
        set AppleScript's text item delimiters to ""
        set s to s as string
    on error errMsg number errNum
        set AppleScript's text item delimiters to otid
        error errMsg number errNum
    end try
    set AppleScript's text item delimiters to otid
    return s
end stripSlash

你能用/symbols来分享一个变量值的例子吗?42(根据道格拉斯·亚当斯的幽默科幻小说《银河系漫游指南》),所以为了整合它,我将用answer替换s来实现,在你的脚本底部包含这个处理程序,然后在你调用“my strip()”之后,你可以将答案设置为我的斜杠(答案)”