我有以下AppleScript。运行时,它会在浏览器窗口中复制当前突出显示的文本,并获取复制的文本并将其以curl形式传递给POST API。唯一的问题是,如果突出显示的文本包含特殊字符,例如'('那么它会失败,带有意外的标记。
我如何正确地逃避复制的文本?
on run {input, parameters}
-- Takes current highlighted work and passes as variable to bot api, which then adds it to the DB of highlights for processing.
delay 3
tell application "Google Chrome"
set theURL to (get URL of active tab of window 1)
set pgTitl to (get title of active tab of front window)
end tell
activate application "Google Chrome"
tell application "System Events"
keystroke "c" using command down
delay 0.5
set copiedtext to the clipboard
end tell
set x to do shell script "curl -F text='" & copiedtext & "' -F color=blue -F source_url=" & theURL & " -F source_id=" & theURL & " -F source_title=" & theURL & " https://www.website.com/api/v1/?token=xxxxxxxxxxxxx"
display notification "Complete." with title " Highlight " subtitle "Highlight"
return input
end run