日本語ドメイン名のエンコード値を取得する
AppleScript サンプルコード
行番号 | ソース |
---|---|
001 | #!/usr/bin/env osascript |
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
003 | # |
004 | # |
005 | # |
006 | #com.cocolog-nifty.quicktimer.icefloe |
007 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
008 | use AppleScript version "2.8" |
009 | use framework "Foundation" |
010 | use framework "AppKit" |
011 | use scripting additions |
012 | |
013 | property refMe : a reference to current application |
014 | |
015 | ################################ |
016 | ##デフォルトクリップボードからテキスト取得 |
017 | ################################ |
018 | set appPasteboard to refMe's NSPasteboard's generalPasteboard() |
019 | set ocidTypeArray to appPasteboard's types() |
020 | set boolContain to ocidTypeArray's containsObject:("public.utf8-plain-text") |
021 | if boolContain = true then |
022 | try |
023 | set ocidPasteboardArray to appPasteboard's readObjectsForClasses:({refMe's NSString}) options:(missing value) |
024 | set ocidPasteboardStrings to ocidPasteboardArray's firstObject() |
025 | on error |
026 | set ocidStringData to appPasteboard's stringForType:("public.utf8-plain-text") |
027 | set ocidPasteboardStrings to (refMe's NSString's stringWithString:(ocidStringData)) |
028 | end try |
029 | else |
030 | set ocidPasteboardStrings to (refMe's NSString's stringWithString:("")) |
031 | end if |
032 | set strDefaultAnswer to ocidPasteboardStrings as text |
033 | |
034 | ################################ |
035 | ######ダイアログ |
036 | ################################ |
037 | #####ダイアログを前面に |
038 | tell current application |
039 | set strName to name as text |
040 | end tell |
041 | ####スクリプトメニューから実行したら |
042 | if strName is "osascript" then |
043 | tell application "Finder" to activate |
044 | else |
045 | tell current application to activate |
046 | end if |
047 | set aliasIconPath to (POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/BookmarkIcon.icns") as alias |
048 | try |
049 | set strMes to ("日本語ドメイン名をhttp://日本語.jp/等URL形式でペースト") as text |
050 | |
051 | set recordResponse to (display dialog strMes with title "入力してください" default answer strDefaultAnswer buttons {"OK", "キャンセル"} default button "OK" cancel button "キャンセル" with icon aliasIconPath giving up after 20 without hidden answer) |
052 | on error |
053 | log "エラーしました" |
054 | return "エラーしました" |
055 | end try |
056 | if true is equal to (gave up of recordResponse) then |
057 | return "時間切れですやりなおしてください" |
058 | end if |
059 | if "OK" is equal to (button returned of recordResponse) then |
060 | set strResponse to (text returned of recordResponse) as text |
061 | else |
062 | log "キャンセルしました" |
063 | return "キャンセルしました" |
064 | end if |
065 | |
066 | ############################## |
067 | ###URLと通常テキストの処理を分岐する |
068 | ##URLの場合 |
069 | set ocidTextString to refMe's NSString's stringWithString:(strResponse) |
070 | if strResponse starts with "http" then |
071 | #webURL |
072 | set ocidURL to refMe's NSURL's alloc()'s initWithString:(ocidTextString) |
073 | set strTextToEncoded to ocidURL's absoluteString() as text |
074 | else if strResponse starts with "file:/" then |
075 | return "エラー" |
076 | else |
077 | #通常文字列 |
078 | return "エラー" |
079 | end if |
080 | |
081 | |
082 | ################################ |
083 | ######ダイアログ |
084 | ################################ |
085 | #####ダイアログを前面に |
086 | tell current application |
087 | set strName to name as text |
088 | end tell |
089 | ####スクリプトメニューから実行したら |
090 | if strName is "osascript" then |
091 | tell application "Finder" to activate |
092 | else |
093 | tell current application to activate |
094 | end if |
095 | set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns" |
096 | set strMes to ("戻り値です\r" & strTextToEncoded) as text |
097 | |
098 | set recordResult to (display dialog strMes with title "エンコード結果" default answer strTextToEncoded buttons {"クリップボードにコピー", "キャンセル", "OK"} default button "OK" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer) |
099 | |
100 | if button returned of recordResult is "クリップボードにコピー" then |
101 | try |
102 | set strText to text returned of recordResult as text |
103 | ####ペーストボード宣言 |
104 | set appPasteboard to refMe's NSPasteboard's generalPasteboard() |
105 | set ocidText to (refMe's NSString's stringWithString:(strText)) |
106 | appPasteboard's clearContents() |
107 | appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString) |
108 | on error |
109 | tell application "Finder" |
110 | set the clipboard to strText as text |
111 | end tell |
112 | end try |
113 | end if |
114 | |
115 | return |
AppleScriptで生成しました |
| 固定リンク