Skip to content

Instantly share code, notes, and snippets.

@zarigani
Created May 14, 2010 12:06
Show Gist options
  • Select an option

  • Save zarigani/401071 to your computer and use it in GitHub Desktop.

Select an option

Save zarigani/401071 to your computer and use it in GitHub Desktop.

Revisions

  1. zarigani created this gist May 14, 2010.
    34 changes: 34 additions & 0 deletions AppleScript_URL_by_JavaScript.scpt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    tell application "AppleScript Editor"
    activate
    set myString to contents of document 1
    set beforeList to {"%", ASCII character (9), ASCII character (13), ASCII character (13), ASCII character (32), ASCII character (34), "&", "<", ">", "\\", "\""}
    set afterList to {"%25", "%09", "%0a", "%0a", "%20", "%22", "%26", "%3c", "%3e", "\\\\", "\\\""}

    set html1 to "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n</head>\n<body>\n\n<script language=\"JavaScript\">\n<!--\nlocation.href=\""
    set html2 to "\"\nsetTimeout('window.close();', 1000);\n//-->\n</script>\n\n</body>\n</html>\n"

    set oldDel to text item delimiters of AppleScript
    set i to 1
    repeat with x in beforeList
    set text item delimiters of AppleScript to x
    set mylist to every text item of myString
    set text item delimiters of AppleScript to item i of afterList
    set myString to mylist as string
    set i to i + 1
    end repeat
    set text item delimiters of AppleScript to oldDel

    set myString to html1 & "applescript://com.apple.scripteditor?action=new&script=" & myString & html2
    set the clipboard to myString
    end tell

    my message("クリップボード", "AppleScriptをURLに変換して、セットしました。")

    on message(title, msg)
    try
    do shell script "/usr/local/bin/growlnotify " & title & " -m " & quoted form of msg
    on error
    activate
    display alert msg giving up after 1
    end try
    end message