001 | #! /usr/bin/env osascript |
---|
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
---|
003 | # |
---|
004 | # Unarchiverをユーザーアプリケーションフォルダ内にコピーインストール |
---|
005 | # com.cocolog-nifty.quicktimer.icefloe |
---|
006 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
---|
007 | ##自分環境がos12なので2.8にしているだけです |
---|
008 | use AppleScript version "2.8" |
---|
009 | use framework "Foundation" |
---|
010 | use framework "UniformTypeIdentifiers" |
---|
011 | use framework "AppKit" |
---|
012 | use scripting additions |
---|
013 | |
---|
014 | property refMe : a reference to current application |
---|
015 | |
---|
016 | |
---|
017 | ############################## |
---|
018 | #ダウンロードするURL |
---|
019 | set ocidURLComponents to refMe's NSURLComponents's alloc()'s init() |
---|
020 | ocidURLComponents's setScheme:"https" |
---|
021 | ocidURLComponents's setHost:"dl.devmate.com" |
---|
022 | ocidURLComponents's setPath:"/com.macpaw.site.theunarchiver/TheUnarchiver.dmg" |
---|
023 | set ocidURLStrings to ocidURLComponents's |URL|'s absoluteString() |
---|
024 | set ocidURL to refMe's NSURL's alloc()'s initWithString:(ocidURLStrings) |
---|
025 | set ocidFileName to ocidURL's lastPathComponent() |
---|
026 | |
---|
027 | ########################## |
---|
028 | #ゴミ箱に入れる |
---|
029 | set listChkPath to {"/Applications/The Unarchiver.app", "/Applications/Utilities/The Unarchiver.app", "~/Applications/The Unarchiver.app", "~/Applications/Utilities/The Unarchiver.app", "~/Library/Containers/cx.c3.theunarchiver", "~/Library/Containers/com.macpaw.site.theunarchiver"} as list |
---|
030 | |
---|
031 | repeat with itemChkPath in listChkPath |
---|
032 | set strFilePath to (itemChkPath) as text |
---|
033 | set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath)) |
---|
034 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
---|
035 | set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false) |
---|
036 | set appFileManager to refMe's NSFileManager's defaultManager() |
---|
037 | set listDone to (appFileManager's trashItemAtURL:(ocidFilePathURL) resultingItemURL:(ocidFilePathURL) |error| :(reference)) |
---|
038 | if (item 1 of listDone) is true then |
---|
039 | log "正常処理" |
---|
040 | else if (item 2 of listDone) ≠ (missing value) then |
---|
041 | set strErrorNO to (item 2 of listDone)'s code() as text |
---|
042 | set strErrorMes to (item 2 of listDone)'s localizedDescription() as text |
---|
043 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
---|
044 | log "エラーしました" & strErrorNO & strErrorMes |
---|
045 | end if |
---|
046 | |
---|
047 | end repeat |
---|
048 | |
---|
049 | ########################## |
---|
050 | #ユーザーユーティリティ |
---|
051 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationDirectory) inDomains:(refMe's NSUserDomainMask)) |
---|
052 | set ocidApplicationDirPathURL to ocidURLsArray's firstObject() |
---|
053 | set ocidUtilitiesDirPathURL to ocidApplicationDirPathURL's URLByAppendingPathComponent:("Utilities") isDirectory:(true) |
---|
054 | #フォルダ作って |
---|
055 | set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0 |
---|
056 | ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions) |
---|
057 | set listDone to appFileManager's createDirectoryAtURL:(ocidUtilitiesDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference) |
---|
058 | if (item 1 of listDone) is true then |
---|
059 | log "createDirectoryAtURL 正常処理" |
---|
060 | else if (item 2 of listDone) ≠ (missing value) then |
---|
061 | log (item 2 of listDone)'s code() as text |
---|
062 | log (item 2 of listDone)'s localizedDescription() as text |
---|
063 | return "createDirectoryAtURL エラーしました" |
---|
064 | end if |
---|
065 | #localized |
---|
066 | set ocidNullText to refMe's NSString's stringWithString:("") |
---|
067 | set ocidLocalizedPathURL to ocidUtilitiesDirPathURL's URLByAppendingPathComponent:(".localized") isDirectory:(false) |
---|
068 | set listDone to ocidNullText's writeToURL:(ocidLocalizedPathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error| :(reference) |
---|
069 | if (item 1 of listDone) is true then |
---|
070 | log "createDirectoryAtURL 正常処理" |
---|
071 | else if (item 2 of listDone) ≠ (missing value) then |
---|
072 | log (item 2 of listDone)'s code() as text |
---|
073 | log (item 2 of listDone)'s localizedDescription() as text |
---|
074 | return "writeToURL エラーしました" |
---|
075 | end if |
---|
076 | set ocidDistAppFilePathURL to ocidUtilitiesDirPathURL's URLByAppendingPathComponent:("The Unarchiver.app") isDirectory:(true) |
---|
077 | |
---|
078 | |
---|
079 | |
---|
080 | ########################## |
---|
081 | #起動時に削除される項目にダウンロード |
---|
082 | |
---|
083 | set ocidTempDirURL to appFileManager's temporaryDirectory() |
---|
084 | set ocidUUID to refMe's NSUUID's alloc()'s init() |
---|
085 | set ocidUUIDString to ocidUUID's UUIDString |
---|
086 | set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:(true) |
---|
087 | #フォルダを作っておく |
---|
088 | set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0 |
---|
089 | ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions) |
---|
090 | set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error| :(reference) |
---|
091 | if (item 1 of listDone) is true then |
---|
092 | log "createDirectoryAtURL 正常処理" |
---|
093 | else if (item 2 of listDone) ≠ (missing value) then |
---|
094 | log (item 2 of listDone)'s code() as text |
---|
095 | log (item 2 of listDone)'s localizedDescription() as text |
---|
096 | return "createDirectoryAtURL エラーしました" |
---|
097 | end if |
---|
098 | |
---|
099 | |
---|
100 | ########################## |
---|
101 | #NSDATAでダウンロード |
---|
102 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
---|
103 | set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidURL) options:(ocidOption) |error| :(reference) |
---|
104 | if (item 2 of listResponse) = (missing value) then |
---|
105 | log "正常処理" |
---|
106 | set ocidReadData to (item 1 of listResponse) |
---|
107 | else if (item 2 of listResponse) ≠ (missing value) then |
---|
108 | log (item 2 of listResponse)'s code() as text |
---|
109 | log (item 2 of listResponse)'s localizedDescription() as text |
---|
110 | return "エラーしました" |
---|
111 | end if |
---|
112 | |
---|
113 | ############################## |
---|
114 | #保存先 |
---|
115 | set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidFileName) isDirectory:(false) |
---|
116 | #保存 |
---|
117 | set ocidOption to (refMe's NSDataWritingAtomic) |
---|
118 | set listDone to ocidReadData's writeToURL:(ocidSaveFilePathURL) options:(ocidOption) |error| :(reference) |
---|
119 | if (item 1 of listDone) is true then |
---|
120 | log "正常処理" |
---|
121 | else if (item 2 of listDone) ≠ (missing value) then |
---|
122 | log (item 2 of listDone)'s code() as text |
---|
123 | log (item 2 of listDone)'s localizedDescription() as text |
---|
124 | return "エラーしました" |
---|
125 | end if |
---|
126 | |
---|
127 | ############################## |
---|
128 | #マウントポイント |
---|
129 | #保存先 |
---|
130 | set ocidMountPointPathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("MountPoint") isDirectory:(true) |
---|
131 | #フォルダを作っておく |
---|
132 | set listDone to appFileManager's createDirectoryAtURL:(ocidMountPointPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error| :(reference) |
---|
133 | if (item 1 of listDone) is true then |
---|
134 | log "createDirectoryAtURL 正常処理" |
---|
135 | else if (item 2 of listDone) ≠ (missing value) then |
---|
136 | log (item 2 of listDone)'s code() as text |
---|
137 | log (item 2 of listDone)'s localizedDescription() as text |
---|
138 | return "createDirectoryAtURL エラーしました" |
---|
139 | end if |
---|
140 | ############################## |
---|
141 | #ディスクイメージマウント |
---|
142 | set strMountPointPath to (ocidMountPointPathURL's |path|()) as text |
---|
143 | set strSaveFilePath to (ocidSaveFilePathURL's |path|()) as text |
---|
144 | set strCommandText to ("/usr/bin/hdiutil attach \"" & strSaveFilePath & "\" -noverify -nobrowse -noautoopen -mountpoint \"" & strMountPointPath & "\"") as text |
---|
145 | log strCommandText |
---|
146 | try |
---|
147 | do shell script strCommandText |
---|
148 | on error |
---|
149 | return "hdiutil attach エラーしました" |
---|
150 | end try |
---|
151 | |
---|
152 | ############################## |
---|
153 | # |
---|
154 | set ocidDmgAppPathURL to ocidMountPointPathURL's URLByAppendingPathComponent:("The Unarchiver.app") isDirectory:(true) |
---|
155 | |
---|
156 | set appFileManager to refMe's NSFileManager's defaultManager() |
---|
157 | set listDone to (appFileManager's copyItemAtURL:(ocidDmgAppPathURL) toURL:(ocidDistAppFilePathURL) |error| :(reference)) |
---|
158 | if (item 1 of listDone) is true then |
---|
159 | log "正常処理" |
---|
160 | else if (item 2 of listDone) ≠ (missing value) then |
---|
161 | set strErrorNO to (item 2 of listDone)'s code() as text |
---|
162 | set strErrorMes to (item 2 of listDone)'s localizedDescription() as text |
---|
163 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
---|
164 | return "エラーしました" & strErrorNO & strErrorMes |
---|
165 | end if |
---|
166 | |
---|
167 | |
---|
168 | ############################## |
---|
169 | #ディスクイメージ デタッチ |
---|
170 | set strCommandText to ("/usr/bin/hdiutil detach \"" & strMountPointPath & "\" -force") as text |
---|
171 | log strCommandText |
---|
172 | try |
---|
173 | do shell script strCommandText |
---|
174 | on error |
---|
175 | return "hdiutil detach エラーしました" |
---|
176 | end try |
---|
177 | |
---|
178 | ############################## |
---|
179 | #起動 |
---|
180 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
---|
181 | set boolDone to appSharedWorkspace's openURL:(ocidDistAppFilePathURL) |
---|
182 | |
---|
183 | delay 1 |
---|
184 | ############################## |
---|
185 | #終了 |
---|
186 | tell application id "com.macpaw.site.theunarchiver" to quit |
---|