// スクリプトの引数をチェックする
var d = scpt.src.substring(0, scpt.src.lastIndexOf("/")+1);
/\?/.test(scpt.src) ? console.log(decodeURI(scpt.src.substring(scpt.src.lastIndexOf("?")+1))):0;
AppleScriptでJavaScriptを使いたい applescript jsc javascriptcore 具体には、URLをエンコード(url encode)したい時、 set theText to "http://ja.wikipedia.org/wiki/ アップルスクリプト " --JavaScript tell application "Safari" set theURL to ( do JavaScript "encodeURI(\"" & theText & "\")" in document 1) as text log "0=" & theURL end tell (*0=http://ja.wikipedia.org/wiki/%E3%82%A2%E3%83%83%E3%83%97%E3%83%AB%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%97%E3%83%88*) と、Safariを経由して結果を得る方法が考えられるが、Safariを経由せず、ApplescriptでJavaScriptを使えないか探ってみた。 Safariで使われているJavaScriptCoreを直接操作する方法があった。 set theText to "http://ja.wikipedia.org/wiki/ アップルスクリプト " --JavaScript set theURL to do shell script "/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc -e 'print(escape(\"" & theText & "\"))'" log "1=" & theURL (*1=http%3A//ja.wikipedia.org/wiki/%E3%82%A2%E3%83%83%E3%83%9...
AppleScriptでJavaScriptを使いたい ターミナルでJavaScriptを使いたい AppleScriptでJavaScriptを使いたい applescript jsc javascriptcore 具体には、URL全体をエンコード(encodeURI)しておきたい時 下記のように、Sfafariを経由して、JavaScriptを使う事ができるが、Safariが起動してまうし、Safariが起動していてもウィンドウがゼロの時はエラーが出るので、スマートではない。 set theText to " アップルスクリプト " --JavaScript tell application "Safari" set theURL to ( do JavaScript "encodeURI(\"" & theText & "\")" in document 1) as text log "encode=" & theURL (*0=%E3%82%A2%E3%83%83%E3%83%97%E3%83%AB%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%97%E3%83%88*) set theURL to ( do JavaScript "decodeURI(\"" & theText & "\")" in document 1) as text log "decode=" & theURL (*0= アップルスクリプト *) end tell そこで、 do shell script で JavaScriptCore.framework を直接呼んで、URL全体をエンコード(encodeURI)。 ※ encodeURIとencodeURIComponentは上手くエンコードしてれない。 のでURL全体をエンコードしたい場合はリンクを参照。 BWNSUY: AppleScriptでURLエンコード しかし、Safariを通さずJava...