001 | #!/usr/bin/env osascript |
---|
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
---|
003 | #com.cocolog-nifty.quicktimer.icefloe |
---|
004 | # |
---|
005 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
---|
006 | use AppleScript version "2.8" |
---|
007 | use framework "Foundation" |
---|
008 | use framework "UniformTypeIdentifiers" |
---|
009 | use framework "AppKit" |
---|
010 | use scripting additions |
---|
011 | property refMe : a reference to current application |
---|
012 | |
---|
013 | set appFileManager to refMe's NSFileManager's defaultManager() |
---|
014 | |
---|
015 | set strName to (name of current application) as text |
---|
016 | if strName is "osascript" then |
---|
017 | tell application "Finder" to activate |
---|
018 | else |
---|
019 | tell current application to activate |
---|
020 | end if |
---|
021 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDownloadsDirectory) inDomains:(refMe's NSUserDomainMask)) |
---|
022 | set ocidDesktopDirPathURL to ocidURLsArray's firstObject() |
---|
023 | set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias |
---|
024 | set listUTI to {"public.item"} as list |
---|
025 | set strMes to ("ファイルを選んでください\n実行後10秒ほどかかります") as text |
---|
026 | set strPrompt to ("ファイルを選んでください\n実行後10秒ほどかかります") as text |
---|
027 | try |
---|
028 | set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias |
---|
029 | on error |
---|
030 | log "エラーしました" |
---|
031 | return "エラーしました" |
---|
032 | end try |
---|
033 | set aliasFilePath to aliasFilePath as alias |
---|
034 | set strFilePath to (POSIX path of aliasFilePath) as text |
---|
035 | set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath) |
---|
036 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
---|
037 | set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false) |
---|
038 | set strFilePath to ocidFilePathURL's |path|() as text |
---|
039 | |
---|
040 | #出力用のテキスト |
---|
041 | set ocidOutputString to refMe's NSMutableString's alloc()'s initWithCapacity:(0) |
---|
042 | ############################## |
---|
043 | #SHA-1を取得 |
---|
044 | set strCommandText to ("/usr/bin/openssl dgst -sha1 \"" & strFilePath & "\"") |
---|
045 | log "\r" & strCommandText & "\r" |
---|
046 | set strExec to ("/bin/zsh -c '" & strCommandText & "'") as text |
---|
047 | try |
---|
048 | set strResponse to (do shell script strExec) as text |
---|
049 | on error |
---|
050 | set strMes to ("コマンド: " & strCommandText & "でエラーになりました") as text |
---|
051 | display alert strMes giving up after 3 |
---|
052 | end try |
---|
053 | ocidOutputString's appendString:("SHA-1: ") |
---|
054 | ocidOutputString's appendString:("\n") |
---|
055 | ocidOutputString's appendString:(strResponse) |
---|
056 | ocidOutputString's appendString:("\n\n") |
---|
057 | ############################## |
---|
058 | #SHA-256を取得 |
---|
059 | set strCommandText to ("/usr/bin/openssl dgst -sha256 \"" & strFilePath & "\"") |
---|
060 | log "\r" & strCommandText & "\r" |
---|
061 | set strExec to ("/bin/zsh -c '" & strCommandText & "'") as text |
---|
062 | try |
---|
063 | set strResponse to (do shell script strExec) as text |
---|
064 | on error |
---|
065 | set strMes to ("コマンド: " & strCommandText & "でエラーになりました") as text |
---|
066 | display alert strMes giving up after 3 |
---|
067 | end try |
---|
068 | ocidOutputString's appendString:("SHA-256: ") |
---|
069 | ocidOutputString's appendString:("\n") |
---|
070 | ocidOutputString's appendString:(strResponse) |
---|
071 | ocidOutputString's appendString:("\n\n") |
---|
072 | |
---|
073 | ############################## |
---|
074 | #md5を取得 |
---|
075 | set strCommandText to ("/usr/bin/openssl dgst -md5 \"" & strFilePath & "\"") |
---|
076 | log "\r" & strCommandText & "\r" |
---|
077 | set strExec to ("/bin/zsh -c '" & strCommandText & "'") as text |
---|
078 | try |
---|
079 | set strResponse to (do shell script strExec) as text |
---|
080 | on error |
---|
081 | set strMes to ("コマンド: " & strCommandText & "でエラーになりました") as text |
---|
082 | display alert strMes giving up after 3 |
---|
083 | end try |
---|
084 | ocidOutputString's appendString:("md5: ") |
---|
085 | ocidOutputString's appendString:("\n") |
---|
086 | ocidOutputString's appendString:(strResponse) |
---|
087 | ocidOutputString's appendString:("\n\n") |
---|
088 | |
---|
089 | |
---|
090 | set ocidOutputString to (ocidOutputString's stringByReplacingOccurrencesOfString:(strFilePath) withString:("")) |
---|
091 | set ocidOutputString to (ocidOutputString's stringByReplacingOccurrencesOfString:(" ") withString:("")) |
---|
092 | set ocidOutputString to (ocidOutputString's stringByReplacingOccurrencesOfString:("=") withString:("")) |
---|
093 | set ocidOutputString to (ocidOutputString's stringByReplacingOccurrencesOfString:("()") withString:("")) |
---|
094 | set ocidOutputString to (ocidOutputString's stringByReplacingOccurrencesOfString:("MD5") withString:("")) |
---|
095 | set ocidOutputString to (ocidOutputString's stringByReplacingOccurrencesOfString:("SHA256") withString:("")) |
---|
096 | set ocidOutputString to (ocidOutputString's stringByReplacingOccurrencesOfString:("SHA1") withString:("")) |
---|
097 | set ocidOutputString to ocidOutputString's uppercaseString() |
---|
098 | |
---|
099 | set strResponse to ocidOutputString as text |
---|
100 | ############################## |
---|
101 | #####ダイアログ |
---|
102 | ############################## |
---|
103 | tell current application |
---|
104 | set strName to name as text |
---|
105 | end tell |
---|
106 | ####スクリプトメニューから実行したら |
---|
107 | if strName is "osascript" then |
---|
108 | tell application "Finder" |
---|
109 | activate |
---|
110 | end tell |
---|
111 | else |
---|
112 | tell current application |
---|
113 | activate |
---|
114 | end tell |
---|
115 | end if |
---|
116 | set aliasIconPath to POSIX file "/System/Library/CoreServices/Finder.app/Contents/Resources/Finder.icns" as alias |
---|
117 | set strMes to "戻り値です" |
---|
118 | try |
---|
119 | set recordResult to (display dialog strMes with title "戻り値です" default answer strResponse buttons {"クリップボードにコピー", "終了", "再実行"} default button "再実行" cancel button "終了" giving up after 20 with icon aliasIconPath without hidden answer) as record |
---|
120 | on error |
---|
121 | return "エラーしました" |
---|
122 | end try |
---|
123 | if (gave up of recordResult) is true then |
---|
124 | return "時間切れです" |
---|
125 | end if |
---|
126 | ############################## |
---|
127 | #####自分自身を再実行 |
---|
128 | ############################## |
---|
129 | if button returned of recordResult is "再実行" then |
---|
130 | tell application "Finder" |
---|
131 | set aliasPathToMe to (path to me) as alias |
---|
132 | end tell |
---|
133 | run script aliasPathToMe with parameters "再実行" |
---|
134 | end if |
---|
135 | ############################## |
---|
136 | #####値のコピー |
---|
137 | ############################## |
---|
138 | if button returned of recordResult is "クリップボードにコピー" then |
---|
139 | try |
---|
140 | set strText to text returned of recordResult as text |
---|
141 | ####ペーストボード宣言 |
---|
142 | set appPasteboard to refMe's NSPasteboard's generalPasteboard() |
---|
143 | set ocidText to (refMe's NSString's stringWithString:(strText)) |
---|
144 | appPasteboard's clearContents() |
---|
145 | appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString) |
---|
146 | on error |
---|
147 | tell application "Finder" |
---|
148 | set the clipboard to strText as text |
---|
149 | end tell |
---|
150 | end try |
---|
151 | end if |
---|
152 | |
---|
153 | |
---|
154 | return ocidOutputString as text |
---|
155 | |
---|
156 | |
---|