指定したAppleScript書類の内容を読み取って、URL文字列に変換するAppleScriptです。
XML-RPC経由でWordPressにAppleScriptのプログラムをHTML化して掲載する時とか、PDFに対して「applescript://」カスタムプロトコルリンクを付加する処理を書いたときに使用しました。クリックすると内容がスクリプトエディタに転送されるリンクを作成するためのものです。
AppleScript名:指定パスのAppleScript書類の内容をURL文字列化 v2 |
— Created 2018-03-28 by Takaaki Naganoya — 2018 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "OSAKit" use framework "AppKit" property quotChar : string id 34 set asPath to choose file of type {"com.apple.applescript.script", "com.apple.applescript.script-bundle"} set contText to getContentsOfFile(asPath) of me set encText to makeEncodedScript(contText) of me set newLinkText to "applescript://com.apple.scripteditor?action=new&script=" & encText –> "applescript://com.apple.scripteditor?action=new&script=use%20AppleScript%20version%20%222%2E4%22%0D………" –指定AppleScriptファイルのソースコードを取得する(実行専用Scriptからは取得できない) — Original Created 2014-02-23 Shane Stanley on getContentsOfFile(anAlias as {alias, string}) set anHFSpath to anAlias as string set aURL to current application’s |NSURL|’s fileURLWithPath:(POSIX path of anHFSpath) set theScript to current application’s OSAScript’s alloc()’s initWithContentsOfURL:aURL |error|:(missing value) return theScript’s source() as text end getContentsOfFile on makeEncodedScript(contText) set delimA to "★☆temp★☆" set delimB to (retURLencodedStrings(delimA) of me) as text set aList to every paragraph of contText set aClass to class of aList if aClass = list then set aLen to length of aList else set aLen to 1 end if set aaList to {} set delim to AppleScript’s text item delimiters set AppleScript’s text item delimiters to delimA set bList to aList as text set AppleScript’s text item delimiters to delim set aaList to (retURLencodedStrings(bList) of me) as text set search_string to delimB as text set replacement_string to "%0D" as text set bList to replace_chars(aaList, search_string, replacement_string) of me return bList end makeEncodedScript on replace_chars(this_text, search_string, replacement_string) set AppleScript’s text item delimiters to the search_string set the item_list to every text item of this_text set AppleScript’s text item delimiters to the replacement_string set this_text to the item_list as string set AppleScript’s text item delimiters to "" return this_text end replace_chars on retURLencodedStrings(aText) set aStr to current application’s NSString’s stringWithString:aText set encodedStr to aStr’s stringByAddingPercentEncodingWithAllowedCharacters:(current application’s NSCharacterSet’s alphanumericCharacterSet()) return encodedStr as text end retURLencodedStrings |
More from my site
(Visited 51 times, 1 visits today)