| 001 | #!/usr/bin/env osascript |
| 002 | #coding: utf-8 |
| 003 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7-- |
| 004 | (* |
| 005 |
|
| 006 | ダウンロードフォルダにダウンロードする『だけ』の単機能 |
| 007 | ダウンロードファイルが署名されていない場合に |
| 008 | アトリビュートの削除を行うパターン |
| 009 |
|
| 010 |
|
| 011 |
|
| 012 | v1 初回作成 |
| 013 |
|
| 014 | com.cocolog-nifty.quicktimer.icefloe *) |
| 015 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7-- |
| 016 | use AppleScript version "2.8" |
| 017 | use framework "Foundation" |
| 018 | use framework "AppKit" |
| 019 | use framework "UniformTypeIdentifiers" |
| 020 | use scripting additions |
| 021 |
|
| 022 | property refMe : a reference to current application |
| 023 | set appFileManager to refMe's NSFileManager's defaultManager() |
| 024 |
|
| 025 |
|
| 026 | ############################ |
| 027 | #バージョン番号を取得する |
| 028 | set strVerURL to ("https://exiftool.org/ver.txt") as text |
| 029 | set ocidVerURLStr to refMe's NSString's stringWithString:(strVerURL) |
| 030 | set ocidVerURL to refMe's NSURL's alloc()'s initWithString:(ocidVerURLStr) |
| 031 | set ocidVerText to refMe's NSString's stringWithContentsOfURL:(ocidVerURL) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference) |
| 032 | set strVer to (first item of ocidVerText) as text |
| 033 |
|
| 034 | ############################ |
| 035 | #ファイル名 |
| 036 | set strSaveFileName to ("ExifTool-" & strVer & ".pkg") as text |
| 037 | #URL |
| 038 | set strURL to ("https://exiftool.org/" & strSaveFileName & "") as text |
| 039 | set ocidURLStr to refMe's NSString's stringWithString:(strURL) |
| 040 | set ocidURL to refMe's NSURL's alloc()'s initWithString:(ocidURLStr) |
| 041 | #ダウンロード先(ダウンロードフォルダ) |
| 042 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDownloadsDirectory) inDomains:(refMe's NSUserDomainMask)) |
| 043 | set ocidDownloadsDirPathURL to ocidURLsArray's firstObject() |
| 044 | set ocidSaveFilePathURL to ocidDownloadsDirPathURL's URLByAppendingPathComponent:(strSaveFileName) isDirectory:(false) |
| 045 |
|
| 046 | ############################ |
| 047 | #NSData'sダウンロード |
| 048 | set ocidOption to (refMe's NSDataReadingMappedAlways) |
| 049 | set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidURL) options:(ocidOption) |error|:(reference) |
| 050 | if (item 2 of listResponse) = (missing value) then |
| 051 | log "正常処理" |
| 052 | set ocidPkgData to (item 1 of listResponse) |
| 053 | else if (item 2 of listResponse) ≠ (missing value) then |
| 054 | set strErrorNO to (item 2 of listResponse)'s code() as text |
| 055 | set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text |
| 056 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
| 057 | return "エラーしました" & strErrorNO & strErrorMes |
| 058 | end if |
| 059 |
|
| 060 | ############################ |
| 061 | #NSData's保存 |
| 062 | set ocidOption to (refMe's NSDataWritingAtomic) |
| 063 | set listDone to ocidPkgData's writeToURL:(ocidSaveFilePathURL) options:(ocidOption) |error|:(reference) |
| 064 | if (first item of listDone) is true then |
| 065 | log "正常処理" |
| 066 | else if (second item of listDone) ≠ (missing value) then |
| 067 | set strErrorNO to (second item of listDone)'s code() as text |
| 068 | set strErrorMes to (second item of listDone)'s localizedDescription() as text |
| 069 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
| 070 | return "エラーしました" & strErrorNO & strErrorMes |
| 071 | end if |
| 072 |
|
| 073 | ############################ |
| 074 | #アトリビュート削除 |
| 075 | set ocidSaveFilePath to (ocidSaveFilePathURL's |path|()) |
| 076 | set strCmd to ("/usr/bin/xattr -rc '" & ocidSaveFilePath & "'") as text |
| 077 | try |
| 078 | do shell script strCmd |
| 079 | on error strErrMsg number numErrNo |
| 080 | log "No: " & numErrNo & linefeed & "Error:" & strErrMsg |
| 081 | return false |
| 082 | end try |
| 083 |
|
| 084 |
|
| 085 | ############################ |
| 086 | #保存先を開く |
| 087 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
| 088 | set boolDone to appSharedWorkspace's openURL:(ocidDownloadsDirPathURL) |
| 089 |
|
| 090 | ############################ |
| 091 | #選択 |
| 092 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
| 093 | set ocidOpenURLsArray to (refMe's NSMutableArray's alloc()'s initWithCapacity:0) |
| 094 | (ocidOpenURLsArray's addObject:(ocidSaveFilePathURL)) |
| 095 | appSharedWorkspace's activateFileViewerSelectingURLs:(ocidOpenURLsArray) |
| 096 |
|
| 097 |
|
| 098 | ############################ |
| 099 | #終了 |
| 100 | set ocidPkgData to (missing value) |
| 101 | try |
| 102 | with timeout of 5 seconds |
| 103 | tell application "System Events" to quit |
| 104 | end timeout |
| 105 | end try |
| 106 |
|
| 107 | return 0 |