20260321

[AppleScript]exiftoolダウンロード ダウンロードした後に アトリビュートを削除するところまで


[AppleScript]exiftoolダウンロード ダウンロードした後に アトリビュートを削除するところまで


【スクリプトエディタで開く】 |

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