传递给 JavaScript 的 AppleScript 变量
AppleScript variables passed to JavaScript
我将TextEdit中的文本存储在AppleScript变量中,我想将其传递给JavaScript。我以为我做得对,但我仍然无法存储值。代码如下:
tell application "TextEdit"
activate
set docText to the text of the front document --This works. I've checked.
end tell
tell application "Google Chrome"
tell window 1
tell active tab
execute javascript "function encryptDocument() {
plainText = '" & docText & "';
return plainText;
} encryptDocument();"
set skurp to the result
display dialog skurp
end tell
end tell
end tell
我将 JavaScript 代码存放在 tell application "Google Chrome"
命令中的原因是,每次尝试在上一个 tell application "TextEdit"
命令中调用它时,我都会收到错误。该错误总是说它期望行尾,但发现"
。不太确定为什么,但我找不到解决此问题的方法。
您要为变量提供的值(我的意思是文本编辑器中的文本)是否有可能包含单引号 (')?没有 ' 在文本编辑器中,这似乎对我有用。
以下代码片段可用于转义单引号。(改编自此代码)
on escape(this_text)
set AppleScript's text item delimiters to the "'"
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the "'''"
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end escape
tell application "TextEdit"
activate
set docText to the text of the front document --This works. I've checked.
end tell
set docText to escape(docText)
tell application "Google Chrome"
tell window 1
tell active tab
execute javascript "function encryptDocument() {
plainText = '" & docText & "';
return plainText;
} encryptDocument();"
set skurp to the result
display dialog skurp
end tell
end tell
end tell
相关文章:
- 将函数的上下文应用于javascript变量
- 无法导出函数expressjs/requestjs中的变量
- 函数参数中的数据与指定变量之间的任何性能差异
- 将PHP变量传递给jQuery时遇到问题
- 如何通过ajax刷新JSF填充的javascript变量
- 参数变量出现ngTable指令问题
- 通过javascript重定向html传递php变量
- 将jsp文件下拉列表中的选定项分配给一个java变量(比如String selection)
- 全局变量和全局对象的属性之间有什么区别吗
- 如何在Bootstrap Modal中为动态点击生成的变量设置jade属性
- 值对象在某个变量发生更改后发生更改
- Javascript变量赋值|
- AngularJS-在JSON选择器中使用变量名
- Javascript计数器变量未显示正确的值
- delete关键字在全局变量上的不同行为
- 如何在php变量中嵌入JQuery代码
- 传递给 JavaScript 的 AppleScript 变量
- 将 applescript 变量传递给 Javascript
- Javascript变量转换为Applescript
- 将Javascript变量返回到AppleScript