Javascript代码无法从Applescript运行?

Javascript代码无法从Applescript运行?,javascript,applescript,Javascript,Applescript,我已经开始学习Applescript——不懂JavaScript——但在让代码正常工作时遇到了问题 我试图在Safari中打开一个网页,一旦该网页加载完毕,对其执行一些javascript javascript是从bookmarklet复制的-当我使用bookmarklet按钮时,javascript按预期工作。但是,当运行我的Applescript时,它返回一个“缺少值”错误,并且对网页不做任何操作 以下是Applescript: set makeReadable to "javascript

我已经开始学习Applescript——不懂JavaScript——但在让代码正常工作时遇到了问题

我试图在Safari中打开一个网页,一旦该网页加载完毕,对其执行一些javascript

javascript是从bookmarklet复制的-当我使用bookmarklet按钮时,javascript按预期工作。但是,当运行我的Applescript时,它返回一个“缺少值”错误,并且对网页不做任何操作

以下是Applescript:

set makeReadable to "javascript:(function()%7B_readableOptions=%7B'text_font':'quote(Palatino Linotype), Palatino, quote(Book Antigua), Georgia, serif','text_font_monospace':'quote(Courier New), Courier, monospace','text_font_header':'quote(Times New Roman), Times, serif','text_size':'14px','text_line_height':'1.5','box_width':'30em','color_text':'%23282828','color_background':'%23F5F5F5','color_links':'%230000FF','text_align':'normal','base':'blueprint','custom_css':''%7D;if(document.getElementsByTagName('body').length>0);else%7Breturn;%7Dif(window.$readable)%7Bif(window.$readable.bookmarkletTimer)%7Breturn;%7D%7Delse%7Bwindow.$readable=%7B%7D;%7Dwindow.$readable.bookmarkletTimer=true;window.$readable.options=_readableOptions;if(window.$readable.bookmarkletClicked)%7Bwindow.$readable.bookmarkletClicked();return;%7D_readableScript=document.createElement('script');_readableScript.setAttribute('src','http://readable-static.tastefulwords.com/target.js?rand='+encodeURIComponent(Math.random()));document.getElementsByTagName('body')%5B0%5D.appendChild(_readableScript);%7D)();"

tell application "Safari"
set theURL to "http://en.wikipedia.org/wiki/Rocky"
open location theURL
delay 20

set SelectedPage to document of window 1
do JavaScript makeReadable in SelectedPage
delay 15
end tell

非常感谢您的帮助

您不能只将bookmarklet(可执行URL)粘贴到
doJavaScript

我没有使用AppleScript的经验,但请尝试

set makeReadable to "(function(){_readableOptions={'text_font':'quote(Palatino Linotype), Palatino, quote(Book Antigua), Georgia, serif','text_font_monospace':'quote(Courier New), Courier, monospace','text_font_header':'quote(Times New Roman), Times, serif','text_size':'14px','text_line_height':'1.5','box_width':'30em','color_text':'#282828','color_background':'#F5F5F5','color_links':'#0000FF','text_align':'normal','base':'blueprint','custom_css':''};if(document.getElementsByTagName('body').length>0);else{return;}if(window.$readable){if(window.$readable.bookmarkletTimer){return;}}else{window.$readable={};}window.$readable.bookmarkletTimer=true;window.$readable.options=_readableOptions;if(window.$readable.bookmarkletClicked){window.$readable.bookmarkletClicked();return;}_readableScript=document.createElement('script');_readableScript.setAttribute('src','http://readable-static.tastefulwords.com/target.js?rand='+encodeURIComponent(Math.random()));document.getElementsByTagName('body')[0].appendChild(_readableScript);})();"

您不能只将bookmarklet(可执行URL)粘贴到
doJavaScript

我没有使用AppleScript的经验,但请尝试

set makeReadable to "(function(){_readableOptions={'text_font':'quote(Palatino Linotype), Palatino, quote(Book Antigua), Georgia, serif','text_font_monospace':'quote(Courier New), Courier, monospace','text_font_header':'quote(Times New Roman), Times, serif','text_size':'14px','text_line_height':'1.5','box_width':'30em','color_text':'#282828','color_background':'#F5F5F5','color_links':'#0000FF','text_align':'normal','base':'blueprint','custom_css':''};if(document.getElementsByTagName('body').length>0);else{return;}if(window.$readable){if(window.$readable.bookmarkletTimer){return;}}else{window.$readable={};}window.$readable.bookmarkletTimer=true;window.$readable.options=_readableOptions;if(window.$readable.bookmarkletClicked){window.$readable.bookmarkletClicked();return;}_readableScript=document.createElement('script');_readableScript.setAttribute('src','http://readable-static.tastefulwords.com/target.js?rand='+encodeURIComponent(Math.random()));document.getElementsByTagName('body')[0].appendChild(_readableScript);})();"

bookmarklet的作用是什么?它将一篇标准网页文章转换为“可读”格式,类似于Safari内置的“阅读器”功能。你的延迟时间太长了,只是在打开位置后延迟1,你应该在延迟方面做得很好,当我试图弄清楚为什么它不起作用时,它们才那么长。。。我想它可能跑得太快了:)不过谢谢!bookmarklet的作用是什么?它将一篇标准网页文章转换为“可读”格式,类似于Safari内置的“阅读器”功能。你的延迟时间太长了,只是在打开位置后延迟1,你应该在延迟方面做得很好,当我试图弄清楚为什么它不起作用时,它们才那么长。。。我想它可能跑得太快了:)不过谢谢!成功了!非常感谢。现在,请通读您所做的更改,并了解如何在将来应用它。。。再次感谢!我刚刚将实体%XX更改为它们相应的字符{}[]和#这很有效!非常感谢。现在,请通读您所做的更改,并了解如何在将来应用它。。。再次感谢!我刚刚将实体%XX更改为其相应的字符{}[]和#