Archive

[Archive Utility]初期設定 設定を変更する

推奨設定.scpt

AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
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##自分環境がos12なので2.8にしているだけです
007use AppleScript version "2.8"
008use framework "Foundation"
009use scripting additions
010
011property refMe : a reference to current application
012
013###UTI
014set strBundleID to "com.apple.archiveutility" as text
015
016tell application id strBundleID to quit
017
018##########################################
019###【1】ドキュメントのパス
020set appFileManager to refMe's NSFileManager's defaultManager()
021set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
022set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
023#旧パス
024set ocidFilePathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Preferences/com.apple.archiveutility.plist") isDirectory:(false)
025#新パス
026set ocidFilePathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Containers/com.apple.archiveutility/Data/Library/Preferences/com.apple.archiveutility.plist") isDirectory:(false)
027
028##########################################
029### 【2】PLISTを可変レコードとして読み込み
030
031set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidFilePathURL)
032
033##########################################
034### 【3】処理はここで
035set ocidStringValue to refMe's NSString's stringWithString:(".")
036(ocidPlistDict's setObject:(ocidStringValue) forKey:("dearchive-into"))
037
038set ocidStringValue to refMe's NSString's stringWithString:(".")
039(ocidPlistDict's setObject:(ocidStringValue) forKey:("archive-info -string"))
040
041set ocidStringValue to refMe's NSString's stringWithString:("~/.Trash")
042(ocidPlistDict's setObject:(ocidStringValue) forKey:("dearchive-move-after"))
043
044set ocidStringValue to refMe's NSString's stringWithString:(".")
045(ocidPlistDict's setObject:(ocidStringValue) forKey:("archive-move-after"))
046
047set ocidStringValue to refMe's NSString's stringWithString:("zip")
048(ocidPlistDict's setObject:(ocidStringValue) forKey:("archive-format"))
049
050set ocidBoolValue to (refMe's NSNumber's numberWithBool:true)
051(ocidPlistDict's setObject:(ocidBoolValue) forKey:("dearchive-recursively"))
052
053set ocidBoolValue to (refMe's NSNumber's numberWithBool:true)
054(ocidPlistDict's setObject:(ocidBoolValue) forKey:("archive-reveal-after"))
055
056set ocidBoolValue to (refMe's NSNumber's numberWithBool:true)
057(ocidPlistDict's setObject:(ocidBoolValue) forKey:("dearchive-reveal-after"))
058
059##########################################
060####【4】保存  ここは上書き
061set listResponse to ocidPlistDict's writeToURL:(ocidFilePathURL) |error| :(reference)
062set boolDone to (item 1 of listResponse)
063-->システムファイルなの書き込めないので書き込み失敗でfalseが返る
064log boolDone
065
066set strCommandText to "/usr/bin/killall cfprefsd" as text
067do shell script strCommandText
068
069return "処理終了"
AppleScriptで生成しました

|

[7zz]パスワード付き圧縮 ドロップレット(7zzを24.09にアップデート)



脆弱性が出たので7-Zip 24.09にアップデートした

ダウンロード - 7zzdroplet.zip



pdfToolbox15.acroplugin等けっこう7zzを内蔵しているアプリはあるので
Acrobatもインストーラーに内蔵されていたりする
7zzでいちどファイル検索してみるといいと思います

AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004# 7zzを利用します(個別にインストールする必要があります)
005# https://github.com/force4u/AppleScript/tree/main/Script%20Menu/Applications/7zz
006#
007# com.cocolog-nifty.quicktimer.icefloe
008----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
009use AppleScript version "2.6"
010use framework "Foundation"
011use framework "AppKit"
012use scripting additions
013
014property refMe : a reference to current application
015
016on run
017  log "ドロップレット限定用"
018  set strAlertMes to "ファイルかフォルダをドロップしてください" as text
019  try
020    set recordResponse to (display alert ("【ドロップレットです】\r" & strAlertMes) as informational giving up after 10) as record
021  on error
022    log "エラーしました"
023    return "キャンセルしました。処理を中止します。インストールが必要な場合は再度実行してください"
024  end try
025  if true is equal to (gave up of recordResponse) then
026    return "時間切れです。処理を中止します。インストールが必要な場合は再度実行してください"
027  end if
028  return
029end run
030
031
032on open listDropObject
033  ###NSFileManager初期化
034  set appFileManager to refMe's NSFileManager's defaultManager()
035  ###Path to me
036  tell application "Finder"
037    set aliasPathToMe to (path to me) as alias
038  end tell
039  #######7zzを アプリケーションに内包する場合
040  ###UNIXパス
041  set strPathToMe to (POSIX path of aliasPathToMe) as text
042  ##7zzバイナリーへのパス
043  set strBinPath to (strPathToMe & "/Contents/bin/7zz") as text
044  #######7zzのパスを指定する場合
045  ##    set strBinPath to ("/some/path/bin/7zz") as text
046  
047  ###ドロップの数だけ繰返し
048  repeat with itemDropObject in listDropObject
049    #################################
050    ###処理する判定
051    set boolChkAliasPath to true as boolean
052    try
053      tell application "Finder"
054        set strKind to (kind of itemDropObject) as text
055      end tell
056    on error
057      log "シンボリックリンク等kindを取得できないファイルは処理しない"
058      set boolChkAliasPath to false as boolean
059    end try
060    if strKind is "アプリケーション" then
061      log "アプリケーションは処理しない"
062      set boolChkAliasPath to false as boolean
063    else if strKind is "ボリューム" then
064      log "ボリュームは処理しない"
065      set boolChkAliasPath to false as boolean
066    else if strKind is "エイリアス" then
067      log "エイリアスは処理しない"
068      set boolChkAliasPath to false as boolean
069    end if
070    #################################
071    ###trueの場合のみ圧縮処理する
072    if boolChkAliasPath is true then
073      ########################################
074      #####パスワード生成 UUIDを利用
075      ###生成したUUIDからハイフンを取り除く
076      set ocidUUIDString to (refMe's NSMutableString's alloc()'s initWithCapacity:0)
077      set ocidConcreteUUID to refMe's NSUUID's UUID()
078      (ocidUUIDString's setString:(ocidConcreteUUID's UUIDString()))
079      set ocidUUIDRange to (ocidUUIDString's rangeOfString:ocidUUIDString)
080      (ocidUUIDString's replaceOccurrencesOfString:("-") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidUUIDRange)
081      set strOwnerPassword to ocidUUIDString as text
082      ########################################
083      #####パス
084      set strFilePath to (POSIX path of itemDropObject) as text
085      set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
086      set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
087      set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false)
088      set ocidDirName to ocidFilePathURL's lastPathComponent()
089      set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
090      set strDirName to ocidDirName as text
091      set strMakeDirName to (strDirName & "_圧縮済")
092      set ocidBaseFilePathURL to (ocidContainerDirPathURL's URLByAppendingPathComponent:strMakeDirName)
093      #####################
094      ###フォルダを作る
095      set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
096      (ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions))
097      set listBoolMakeDir to (appFileManager's createDirectoryAtURL:(ocidBaseFilePathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference))
098      #####################
099      ###zipPath
100      set ocidDirFilePathURL to (ocidBaseFilePathURL's URLByAppendingPathComponent:(ocidDirName))
101      set ocidZipFilePathURL to (ocidDirFilePathURL's URLByAppendingPathExtension:"zip")
102      set strZipFilePathURL to ocidZipFilePathURL's |path|() as text
103      ########################################
104      #####パスワード生成 UUIDを利用
105      set strTextFileName to strDirName & ".pw.txt"
106      set ocidTextFilePathURL to (ocidBaseFilePathURL's URLByAppendingPathComponent:strTextFileName)
107      ###テキスト
108      set strTextFile to "先にお送りしました圧縮ファイル\n『" & strDirName & "』の\n解凍パスワードをお知らせします\n\n" & strOwnerPassword & "\n\n解凍出来ない等ありましたらお知らせください。\n(パスワードをコピー&ペーストする際に\n改行やスペースが入らないように留意ください)\n" as text
109      set ocidPWString to (refMe's NSString's stringWithString:strTextFile)
110      set ocidUUIDData to (ocidPWString's dataUsingEncoding:(refMe's NSUTF8StringEncoding))
111      #####パスワードを書いたテキストファイルを保存
112      set boolResults to (ocidUUIDData's writeToURL:ocidTextFilePathURL atomically:true)
113      ########################################
114      #####コマンド実行
115      set strCommandText to ("\"" & strBinPath & "\" a \"" & strZipFilePathURL & "\"   -p" & strOwnerPassword & " \"" & strFilePath & "\"")
116      do shell script strCommandText
117    end if
118  end repeat
119  return "処理終了"
120end open
121
AppleScriptで生成しました

|

ファイルのリソースフォークを削除したファイルコピーをしてから圧縮する(失敗作)


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004# ドロップレットとしても使えます
005# ファイル>書き出し>アプリケーション で書き出してください
006# リソースフォークと 拡張属性を削除してから圧縮します
007#
008# オリジナルのファイルをコピーしてからリソース削除するので
009# オリジナルのファイルを改変しないがテーマだったが
010# 結局macOS標準のZIPはUTF8だからWindows互換とはいかない失敗作
011# com.cocolog-nifty.quicktimer.icefloe
012----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
013use AppleScript version "2.6"
014use framework "Foundation"
015use framework "AppKit"
016use framework "UniformTypeIdentifiers"
017use scripting additions
018
019property refMe : a reference to current application
020property strBinPath : "/usr/bin/zip"
021property ocidChosenFileURLarray : missing value
022
023##########################
024#ダイアログ本体
025##########################
026on appChooseFile:(ocidArgDirPathURL)
027  #
028  set ocidOpenPanel to refMe's NSOpenPanel's openPanel()
029  ocidOpenPanel's setDirectoryURL:(ocidArgDirPathURL)
030  ocidOpenPanel's setCanChooseFiles:(true)
031  ocidOpenPanel's setCanChooseDirectories:(true)
032  ocidOpenPanel's setAllowsMultipleSelection:(true)
033  ocidOpenPanel's setAccessoryViewDisclosed:(true)
034  ocidOpenPanel's setTitle:"ファイルを選択してください"
035  ocidOpenPanel's setPrompt:"実行"
036  ocidOpenPanel's setMessage:"ファイルかフォルダ選んでね"
037  ocidOpenPanel's setShowsTagField:(true)
038  ocidOpenPanel's setResolvesAliases:(false)
039  ocidOpenPanel's setShowsHiddenFiles:(true)
040  ocidOpenPanel's setExtensionHidden:(false)
041  ocidOpenPanel's setCanCreateDirectories:(true)
042  ocidOpenPanel's setCanDownloadUbiquitousContents:(true)
043  ocidOpenPanel's setCanResolveUbiquitousConflicts:(true)
044  ocidOpenPanel's setCanSelectHiddenExtension:(true)
045  ocidOpenPanel's setTreatsFilePackagesAsDirectories:(true)
046  #対象のUTIをてセット
047  set ocidUTIarray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
048  set ocidItemUTType to (refMe's UTType's typeWithIdentifier:("public.item"))
049  (ocidUTIarray's addObject:(ocidItemUTType))
050  ocidOpenPanel's setAllowedContentTypes:(ocidUTIarray)
051  #実行
052  set returnCode to ocidOpenPanel's runModal()
053  #キャンセルをmissing value
054  if returnCode = (refMe's NSModalResponseCancel) then
055    log "キャンセル"
056    error number -128
057  else if returnCode = (refMe's NSModalResponseOK) then
058    log "OK"
059    set my ocidChosenFileURLarray to ocidOpenPanel's |URLs|()
060    
061  end if
062end appChooseFile:
063
064##########################
065#ダイアログ呼び出し
066##########################
067on run
068  tell current application
069    set strName to name as text
070  end tell
071  ###スクリプトメニューから実行したら
072  if strName is "osascript" then
073    tell application "Finder" to activate
074  else
075    tell current application to activate
076  end if
077  ###デフォルトロケーション
078  set appFileManager to refMe's NSFileManager's defaultManager()
079  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
080  set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
081  ###ダイアログ呼び出し
082  my performSelectorOnMainThread:("appChooseFile:") withObject:(ocidDesktopDirPathURL) waitUntilDone:(true)
083  log "A"
084  if ocidChosenFileURLarray = (missing value) then
085    return "キャンセルしました"
086  else
087    log "B"
088    set ocidOkPathURLArray to doSelectURL(ocidChosenFileURLarray)
089  end if
090  log "D"
091  doSendArray2Exec(ocidOkPathURLArray)
092  return
093end run
094
095###################
096# ドロップ
097###################
098on open listAliasFilePath
099  set ocidURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
100  repeat with itemAliasFilePath in listAliasFilePath
101    set strItemFilePath to (POSIX path of itemAliasFilePath) as text
102    set ocidItemFilePathStr to (refMe's NSString's stringWithString:(strItemFilePath))
103    set ocidItemFilePath to ocidItemFilePathStr's stringByStandardizingPath()
104    set ocidItemFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidItemFilePath) isDirectory:false)
105    (ocidURLArray's addObject:(ocidItemFilePathURL))
106  end repeat
107  #パス判定に回す
108  set ocidOkPathURLArray to doSelectURL(ocidURLArray)
109  #次工程に送る
110  doSendArray2Exec(argURLArray)
111  return
112end open
113
114###################
115# タスクへ送る
116###################
117to doSendArray2Exec(argURLArray)
118  repeat with itemFilePathURL in argURLArray
119    log doExecCommand(itemFilePathURL)
120  end repeat
121  return
122end doSendArray2Exec
123
124
125
126###################
127# 対象URL判定
128###################
129to doSelectURL(argFileURLArray)
130  log "C A"
131  #戻し用のARRAY
132  set ocidReturnURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
133  ###ドロップの数だけ繰返し
134  repeat with itemURL in argFileURLArray
135    #URL判定
136    # ファイルとフォルダのみ iCloudを除外
137    set boolURLIS to doURLis(itemURL, (refMe's NSURLIsVolumeKey))
138    if boolURLIS is false then
139      set boolURLIS to doURLis(itemURL, (refMe's NSURLIsAliasFileKey))
140      if boolURLIS is false then
141        set boolURLIS to doURLis(itemURL, (refMe's NSURLIsSymbolicLinkKey))
142        if boolURLIS is false then
143          set boolURLIS to doURLis(itemURL, (refMe's NSURLIsUbiquitousItemKey))
144          if boolURLIS is false then
145            set boolURLIS to doURLis(itemURL, (refMe's NSURLIsRegularFileKey))
146            if boolURLIS is true then
147              (ocidReturnURLArray's addObject:(itemURL))
148            end if
149            set boolURLIS to doURLis(itemURL, (refMe's NSURLIsDirectoryKey))
150            if boolURLIS is true then
151              (ocidReturnURLArray's addObject:(itemURL))
152            end if
153          end if
154        end if
155      end if
156    end if
157  end repeat
158  log "C B"
159  return ocidReturnURLArray
160end doSelectURL
161
162
163
164to doExecCommand(argFilePathURL)
165  ###################
166  #パス
167  (*
168  set strFilePath to (POSIX path of argFilePathURL) as text
169  set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
170  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
171  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false)
172*)
173  set ocidFilePathURL to argFilePathURL
174  set strFilePath to ocidFilePathURL's |path| as text
175  
176  #ファイル名(またはディレクトリ名)
177  set ocidFileName to ocidFilePathURL's lastPathComponent()
178  
179  ###################
180  #日付
181  set strDateno to doGetDateNo("yyyyMMddhhmm")
182  
183  ###################
184  #UUID
185  set ocidUUID to refMe's NSUUID's alloc()'s init()
186  set ocidUUIDString to ocidUUID's UUIDString
187  #ARRAYにして
188  set ocidUUIDArray to (ocidUUIDString's componentsSeparatedByString:("-"))
189  #UUIDの最後の12桁を日付に入れ替える
190  (ocidUUIDArray's replaceObjectAtIndex:(4) withObject:(strDateno))
191  set ocidUUIDString to (ocidUUIDArray's componentsJoinedByString:("-"))
192  
193  ###################
194  #同階層に圧縮完了フォルダ
195  set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
196  set strSetValue to ((ocidFileName as text) & "_圧縮済") as text
197  set ocidDistDirPathURL to (ocidContainerDirPathURL's URLByAppendingPathComponent:(strSetValue) isDirectory:(true))
198  set strDistDirPathURL to ocidDistDirPathURL's |path|() as text
199  #フォルダ作っておく
200  set appFileManager to refMe's NSFileManager's defaultManager()
201  set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
202  (ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions))
203  set listBoolMakeDir to (appFileManager's createDirectoryAtURL:(ocidDistDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference))
204  
205  ###################
206  #出力関連ファイルパス
207  set strSetZipFileName to ((ocidUUIDString as text) & ".zip") as text
208  set ocidZipFilePathURL to (ocidDistDirPathURL's URLByAppendingPathComponent:(strSetZipFileName) isDirectory:(false))
209  set strZipFilePath to ocidZipFilePathURL's |path|() as text
210  set strSetValue to ("設定内容.txt") as text
211  set ocidReadMeFilePathURL to (ocidDistDirPathURL's URLByAppendingPathComponent:(strSetValue) isDirectory:(false))
212  set strReadMeFilePath to ocidReadMeFilePathURL's |path|() as text
213  
214  ###################
215  #テンポラリ パス
216  set ocidTempDirURL to appFileManager's temporaryDirectory()
217  set ocidSaveDirPathURL to (ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true)
218  set strSaveDirPathURL to ocidSaveDirPathURL's |path|() as text
219  
220  ###################
221  #フォルダを生成
222  (ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions))
223  set listDone to (appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference))
224  
225  ###################
226  #テンポラリーにコピー
227  #コピーする前にWINDOWSファイル名セーフを確認する
228  set ocidSafeFileName to doSafeFileName(ocidFileName)
229  #予約語だった場合は置換する
230  set ocidSafeFileName to doReservedFileName(ocidSafeFileName)
231  set ocidTempFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidSafeFileName))
232  # set listDone to (appFileManager's copyItemAtURL:(ocidFilePathURL) toURL:(ocidTempFilePathURL) |error| :(reference))
233  #DITTOを使うことにした
234  set strTempFilePathURL to ocidTempFilePathURL's |path|() as text
235  
236  ###################
237  #リソースフォーク削除
238  set strCommandText to ("/usr/bin/ditto --noextattr --norsrc --noacl --noqtn \"" & strFilePath & "\" \"" & strTempFilePathURL & "\"") as text
239  log strCommandText
240  set objDone to doExecTask(strCommandText)
241  if objDone is false then
242    return "dittoでエラーしました"
243  end if
244  
245  ###################
246  #拡張属性削除
247  set strCommandText to ("/usr/bin/xattr -cr \"" & strSaveDirPathURL & "\"") as text
248  log strCommandText
249  set objDone to doExecTask(strCommandText)
250  if objDone is false then
251    return "xattrでエラーしました"
252  end if
253  
254  ###################
255  #DOT_CLEAN
256  set strCommandText to ("/usr/sbin/dot_clean -n -m  -v  \"" & strSaveDirPathURL & "\"") as text
257  log strCommandText
258  set objDone to doExecTask(strCommandText)
259  if objDone is false then
260    return "dot_cleanでエラーしました"
261  end if
262  
263  ###################
264  #FINDでDSファイル削除
265  set strCommandText to ("/usr/bin/find \"" & strSaveDirPathURL & "\" -name \".DS_Store\" -depth -exec rm {} \\;") as text
266  log strCommandText
267  set objDone to doExecTask(strCommandText)
268  if objDone is false then
269    log "findでエラーしました"
270  end if
271  
272  ###################
273  #パスワード用のUUID
274  set ocidUUID to refMe's NSUUID's alloc()'s init()
275  set ocidUUIDString to ocidUUID's UUIDString
276  set ocidOwnerPassword to (ocidUUIDString's stringByReplacingOccurrencesOfString:("-") withString:(""))
277  set strOwnerPassword to ocidOwnerPassword as text
278  
279  ###################
280  #圧縮
281  set strCommandText to ("" & strBinPath & " -j -X -e -P " & strOwnerPassword & " \"" & strZipFilePath & "\" -r \"" & strSaveDirPathURL & "\"") as text
282  set strCommandText to ("" & strBinPath & " -s 0 -5 -o -j -X -e -P " & strOwnerPassword & "  \"" & strZipFilePath & "\" -r  \"" & strSaveDirPathURL & "\"") as text
283  
284  log strCommandText
285  set objDone to doExecTask(strCommandText)
286  if objDone is false then
287    return "ZIPでエラーしました"
288  end if
289  
290  ###################
291  #ハッシュ
292  set strCommandText to ("/usr/bin/openssl dgst -sha256  \"" & strZipFilePath & "\"") as text
293  log strCommandText
294  set objDone to doExecTask(strCommandText)
295  if objDone is false then
296    return "findでエラーしました"
297  end if
298  set ocidSTDoutArray to (objDone's componentsSeparatedByString:("="))
299  set ocidHASH to ocidSTDoutArray's lastObject()
300  set ocidCharset to refMe's NSCharacterSet's alphanumericCharacterSet
301  set ocidCharsetInvert to ocidCharset's invertedSet()
302  set ocidHASH to (ocidHASH's stringByTrimmingCharactersInSet:(ocidCharsetInvert))
303  
304  ###################
305  # 出力テキスト
306  set ocidOutputString to (refMe's NSMutableString's alloc()'s initWithCapacity:(0))
307  (ocidOutputString's appendString:("先にお送りしました圧縮ファイル"))
308  (ocidOutputString's appendString:("\n『"))
309  (ocidOutputString's appendString:(strSetZipFileName))
310  (ocidOutputString's appendString:("』の\n\n"))
311  (ocidOutputString's appendString:("解凍パスワードをお知らせします"))
312  (ocidOutputString's appendString:("\n\n"))
313  (ocidOutputString's appendString:(strOwnerPassword))
314  (ocidOutputString's appendString:("\n\n"))
315  (ocidOutputString's appendString:("解凍後のファイル名は"))
316  (ocidOutputString's appendString:("\n『"))
317  (ocidOutputString's appendString:(ocidFileName))
318  (ocidOutputString's appendString:("』になります。\n\n"))
319  (ocidOutputString's appendString:("解凍出来ない等ありましたらお知らせください。\n"))
320  (ocidOutputString's appendString:("(パスワードをコピー&ペーストする際に\n"))
321  (ocidOutputString's appendString:("  改行やスペースが入らないように留意ください)\n"))
322  (ocidOutputString's appendString:("\n----\n"))
323  (ocidOutputString's appendString:("HASH: "))
324  (ocidOutputString's appendString:(ocidHASH))
325  (ocidOutputString's appendString:("\n\n"))
326  (ocidOutputString's appendString:("Macでの確認方法: \n"))
327  (ocidOutputString's appendString:("/usr/bin/openssl dgst -sha256 /Users/ユーザー名/Desktop/" & strSetZipFileName & "\"\n"))
328  (ocidOutputString's appendString:("Windows: \n"))
329  (ocidOutputString's appendString:("certutil -hashfile \"C:\\Users\\ユーザー名\\Desktop\\" & strSetZipFileName & "\" SHA256"))
330  (ocidOutputString's appendString:("\n----\n"))
331  (ocidOutputString's appendString:("Windows:解凍時のファイル名の文字バケ\n"))
332  (ocidOutputString's appendString:("7Zipをご利用ください\n"))
333  (ocidOutputString's appendString:("\thttps://www.7-zip.org/\n"))
334  
335  ###################
336  #テキスト保存
337  set ocidSaveData to (ocidOutputString's dataUsingEncoding:(refMe's NSUTF8StringEncoding))
338  set ocidOption to refMe's NSDataWritingAtomic
339  set boolDone to (ocidSaveData's writeToURL:(ocidReadMeFilePathURL) options:(ocidOption) |error| :(reference))
340  
341end doExecCommand
342
343
344
345
346##########################
347# リソースキーチェック
348##########################
349to doURLis(argFilePathURL, argNSURLResourceKey)
350  #キーを格納するArray
351  set ocidKeyArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
352  ocidKeyArray's addObject:(refMe's NSURLIsApplicationKey)
353  ocidKeyArray's addObject:(refMe's NSURLIsDirectoryKey)
354  ocidKeyArray's addObject:(refMe's NSURLIsAliasFileKey)
355  ocidKeyArray's addObject:(refMe's NSURLIsRegularFileKey)
356  ocidKeyArray's addObject:(refMe's NSURLIsPackageKey)
357  ocidKeyArray's addObject:(refMe's NSURLIsVolumeKey)
358  ocidKeyArray's addObject:(refMe's NSURLIsUbiquitousItemKey)
359  ocidKeyArray's addObject:(refMe's NSURLIsSymbolicLinkKey)
360  ocidKeyArray's addObject:(refMe's NSURLIsWritableKey)
361  ocidKeyArray's addObject:(refMe's NSURLIsReadableKey)
362  ocidKeyArray's addObject:(refMe's NSURLIsExecutableKey)
363  ocidKeyArray's addObject:(refMe's NSURLIsUserImmutableKey)
364  ocidKeyArray's addObject:(refMe's NSURLIsSystemImmutableKey)
365  ocidKeyArray's addObject:(refMe's NSURLIsHiddenKey)
366  ocidKeyArray's addObject:(refMe's NSURLIsExcludedFromBackupKey)
367  ocidKeyArray's addObject:(refMe's NSURLIsPurgeableKey)
368  ocidKeyArray's addObject:(refMe's NSURLIsSparseKey)
369  ocidKeyArray's addObject:(refMe's NSURLIsMountTriggerKey)
370  #リソース取得
371  set listResponse to (argFilePathURL's resourceValuesForKeys:(ocidKeyArray) |error| :(reference))
372  set ocidResourceValueDict to (item 1 of listResponse)
373  #判定
374  set boolVolume to ocidResourceValueDict's valueForKey:(argNSURLResourceKey)
375  #判定値を戻す
376  if boolVolume = (missing value) then
377    return false as boolean
378  else
379    return boolVolume as boolean
380  end if
381  
382end doURLis
383
384
385##########################
386# ファイル名互換チェック
387##########################
388to doSafeFileName(argFileName)
389  #テキストかOCIDかわからないので一度テキストにして
390  set strFileName to argFileName as text
391  #その後でNSStringにする
392  set ocidReplacedStrings to (refMe's NSString's stringWithString:(strFileName))
393  #置換テーブル
394  set recordUnsupported to {|\\|:"_", |/|:"_", ||:":", _:"", |*|:"_", |?|:"_", |"|:"_", |<|:"_", |>|:"_"} as record
395  set ocidUnsupportedDict to refMe's NSDictionary's dictionaryWithDictionary:(recordUnsupported)
396  set ocidAllkey to ocidUnsupportedDict's allKeys()
397  set numCntArray to ocidAllkey's |count|()
398  #キーの数だけ繰り返し
399  repeat with itemNo from 0 to (numCntArray - 1) by 1
400    #キーの取得
401    set ocidKey to (ocidAllkey's objectAtIndex:(itemNo))
402    #置換デーブルの値を取得
403    set ocidValue to (ocidUnsupportedDict's valueForKey:(ocidKey))
404    #文字列置換
405    set ocidReplacedStrings to (ocidReplacedStrings's stringByReplacingOccurrencesOfString:(ocidKey) withString:(ocidValue))
406  end repeat
407  #OCIDで戻す場合
408  return ocidReplacedStrings
409  #テキストで戻す場合
410  #   return ocidReplacedStrings as text
411  #
412  
413end doSafeFileName
414
415
416##########################
417# 日付取得
418##########################
419to doGetDateNo(strDateFormat)
420  ###################
421  #日付情報の取得
422  set ocidDate to current application's NSDate's |date|()
423  ###################
424  #日付のフォーマットを定義
425  set ocidNSDateFormatter to current application's NSDateFormatter's alloc()'s init()
426  set ocidLocale to current application's NSLocale's localeWithLocaleIdentifier:("ja_JP_POSIX")
427  ocidNSDateFormatter's setLocale:(ocidLocale)
428  ocidNSDateFormatter's setDateFormat:(strDateFormat)
429  ###################
430  #適応してテキストで戻す
431  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:(ocidDate)
432  set strDateAndTime to ocidDateAndTime as text
433  return strDateAndTime
434end doGetDateNo
435
436##########################
437# コマンド実行
438##########################
439to doExecTask(argCommandText)
440  ###################
441  #引数をテキストに確定
442  set strCommandText to argCommandText as text
443  
444  ###################
445  #テンポラリ
446  set appFileManager to refMe's NSFileManager's defaultManager()
447  set ocidTempDirURL to appFileManager's temporaryDirectory()
448  
449  ###################
450  #ログファイル
451  set strDateno to doGetDateNo("yyyyMMddHHmmss")
452  set strLogFileName to ("scriptlog." & strDateno & ".log") as text
453  set ocidLogFilePathURL to ocidTempDirURL's URLByAppendingPathComponent:(strLogFileName) isDirectory:(false)
454  set ocidLogFilePath to ocidLogFilePathURL's |path|()
455  
456  ##################
457  #ログファイル生成
458  set ocidNulString to refMe's NSString's alloc()'s init()
459  set listDone to ocidNulString's writeToURL:(ocidLogFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error| :(reference)
460  
461  ##################
462  #ログファイルのアクセス権 644
463  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
464  ocidAttrDict's setValue:(420) forKey:(refMe's NSFilePosixPermissions)
465  set listDone to appFileManager's setAttributes:(ocidAttrDict) ofItemAtPath:(ocidLogFilePath) |error| :(reference)
466  
467  ##################
468  #実行時のカレント
469  set ocidCurrentDirPathURL to ocidTempDirURL
470  
471  ################## 
472  #コマンド実行
473  set ocidComString to refMe's NSString's stringWithString:(strCommandText)
474  set ocidTermTask to refMe's NSTask's alloc()'s init()
475  ocidTermTask's setLaunchPath:("/bin/zsh")
476  set ocidArgumentsArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
477  ocidArgumentsArray's addObject:("-c")
478  ocidArgumentsArray's addObject:(ocidComString)
479  ocidTermTask's setArguments:(ocidArgumentsArray)
480  set ocidOutPut to refMe's NSPipe's pipe()
481  set ocidError to refMe's NSPipe's pipe()
482  ocidTermTask's setStandardOutput:(ocidOutPut)
483  ocidTermTask's setStandardError:(ocidError)
484  ocidTermTask's setCurrentDirectoryURL:(ocidCurrentDirPathURL)
485  set listDoneReturn to ocidTermTask's launchAndReturnError:(reference)
486  if (item 1 of listDoneReturn) is (false) then
487    log "エラーコード:" & (item 2 of listDoneReturn)'s code() as text
488    log "エラードメイン:" & (item 2 of listDoneReturn)'s domain() as text
489    log "Description:" & (item 2 of listDoneReturn)'s localizedDescription() as text
490    log "FailureReason:" & (item 2 of listDoneReturn)'s localizedFailureReason() as text
491  end if
492  
493  ##################
494  #終了待ち
495  ocidTermTask's waitUntilExit()
496  
497  ##################
498  #標準出力をログに
499  set ocidOutPutData to ocidOutPut's fileHandleForReading()
500  set listResponse to ocidOutPutData's readDataToEndOfFileAndReturnError:(reference)
501  set ocidStdOut to (item 1 of listResponse)
502  ##これが戻り値
503  set ocidStdOut to refMe's NSString's alloc()'s initWithData:(ocidStdOut) encoding:(refMe's NSUTF8StringEncoding)
504  set listDone to ocidStdOut's writeToURL:(ocidLogFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error| :(reference)
505  
506  ##################
507  #戻り値チェック
508  set numReturnNo to ocidTermTask's terminationStatus() as integer
509  #正常
510  if numReturnNo = 0 then
511    return ocidStdOut
512  else
513    #エラー
514    set ocidErrorData to ocidError's fileHandleForReading()
515    set listResponse to ocidErrorData's readDataToEndOfFileAndReturnError:(reference)
516    set ocidErrorOutData to (item 1 of listResponse)
517    set ocidErrorOutString to refMe's NSString's alloc()'s initWithData:(ocidErrorOutData) encoding:(refMe's NSUTF8StringEncoding)
518    set listResponse to refMe's NSFileHandle's fileHandleForWritingToURL:(ocidLogFilePathURL) |error| :(reference)
519    set ocidReadHandle to (item 1 of listResponse)
520    set listDone to ocidReadHandle's seekToEndReturningOffset:(0) |error| :(reference)
521    log (item 1 of listDone) as boolean
522    set listDone to ocidReadHandle's writeData:(ocidErrorOutData) |error| :(reference)
523    log (item 1 of listDone) as boolean
524    set listDone to ocidReadHandle's closeAndReturnError:(reference)
525    log (item 1 of listDone) as boolean
526    return false
527  end if
528  
529  return false
530  
531end doExecTask
532
533
534##############################
535# 予約語置換
536##############################
537to doReservedFileName(argFileName)
538  #テキストかOCIDかわからないので一度テキストにして
539  set strFileName to argFileName as text
540  #置換テーブル
541  set listReserved to {"COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9", "CON", "PRN", "AUX", "NUL"} as list
542  set numCntArray to (count of every item of listReserved) as integer
543  #キーの数だけ繰り返し
544  repeat with itemNo from 1 to numCntArray by 1
545    #キーの取得
546    set strKey to (item itemNo of listReserved)
547    #置換デーブルの値を取得
548    set strValue to ("_" & strKey) as text
549    #文字列置換
550    if strFileName is strKey then
551      set strFileName to strValue as text
552    end if
553  end repeat
554  #OCIDで戻す場合
555  # return ocidReplacedStrings
556  #テキストで戻す場合
557  return strFileName as text
558  
559end doReservedFileName
AppleScriptで生成しました

|

[zip]EPUB XLSX DOCX PPTX用 非圧縮ZIPアーカイブ



解凍したXLXSやPPTXのフォルダの画像に修正入れて戻す時用



AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004(*
005EPUB XLSX PPTX DOCX等
006指定のフォルダから
007非圧縮のZIPでファイルを生成します
008
009*)
010# com.cocolog-nifty.quicktimer.icefloe
011----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
012use AppleScript version "2.8"
013use framework "Foundation"
014use scripting additions
015
016property refMe : a reference to current application
017
018
019###Wクリックで起動した場合
020on run
021  set aliasDefaultLocation to (path to desktop from user domain) as alias
022  set strPromptText to "フォルダをえらんでください\n非圧縮のZIPでファイルを生成します" as text
023  set strMesText to "フォルダをえらんでください\n非圧縮のZIPでファイルを生成します" as text
024  try
025    set listFolderPath to (choose folder strMesText with prompt strPromptText default location aliasDefaultLocation with multiple selections allowed, invisibles and showing package contents) as list
026  on error
027    log "エラーしました"
028    return "エラーしました"
029  end try
030  open listFolderPath
031end run
032
033###ドロップで起動した場合
034on open listFolderPath
035  tell application "Finder"
036    set strKind to (kind of (item 1 of listFolderPath)) as text
037  end tell
038  if strKind is not "フォルダ" then
039    return "フォルダ以外は処理しない"
040  end if
041  ####構造ファイルの名称を取得する
042  repeat with itemFolderPath in listFolderPath
043    set aliasFolderPath to itemFolderPath as alias
044    tell application "Finder"
045      tell folder aliasFolderPath
046        set listContentsAlias to name of every item as list
047        set strDirName to name as text
048      end tell
049    end tell
050    ####コマンドライン用に第一階層の項目をテキストにする
051    set strDirList to ("") as text
052    set strExtension to (missing value)
053    repeat with itemName in listContentsAlias
054      set strItemName to itemName as text
055      set strDirList to (strDirList & "\"" & strItemName & "\" ") as text
056      #拡張子判定
057      if strItemName is "xl" then
058        set strExtension to "xlsx" as text
059      else if strItemName is "ppt" then
060        set strExtension to "pptx" as text
061      else if strItemName is "word" then
062        set strExtension to "docx" as text
063      else if strItemName is "OPS" then
064        set strExtension to "epub" as text
065      end if
066    end repeat
067    if strExtension = (missing value) then
068      return "フォルダの構造に誤りがあります"
069    end if
070    ###
071    #パス
072    tell application "Finder"
073      set aliasContainerDirPath to (container of aliasFolderPath) as alias
074    end tell
075    set strContainerDirPath to (POSIX path of aliasContainerDirPath) as text
076    set strDirPath to (POSIX path of aliasFolderPath) as text
077    #dot_clean実行
078    set theComandText to ("/usr/sbin/dot_clean -n -m  -v  \"" & strDirPath & "\"") as text
079    do shell script theComandText
080    #FindeでDS_Storeを除去
081    set theCmdCom to ("/usr/bin/find \"" & strDirPath & "\" -name \".DS_Store\" -depth -exec rm {} \\;") as text
082    do shell script theCmdCom
083    #移動
084    set strCommandText to ("/usr/bin/cd  \"" & strDirPath & "\"") as text
085    log strCommandText
086    do shell script strCommandText
087    #移動
088    set strCommandText to ("pushd \"" & strDirPath & "\"") as text
089    log strCommandText
090    do shell script strCommandText
091    #圧縮実行
092    set strCommandText to ("pushd \"" & strDirPath & "\" && '/usr/bin/zip' -rX \"../" & strDirName & "." & strExtension & "\" " & strDirList & "") as text
093    log "\r" & strCommandText & "\r"
094    do shell script strCommandText
095    
096  end repeat
097  
098end open
099
100
101
102
AppleScriptで生成しました

|

[Unarchiver]解凍:Unarchiver

20241011044615_1021x228

メインサイト
https://theunarchiver.com/

コマンドラインツール
https://theunarchiver.com/command-line




[Unarchiver] Unarchiverのmobileconfigによる設定
https://quicktimer.cocolog-nifty.com/icefloe/2024/10/post-51b73e.html

[bash]UnarchiverCLIインストール
https://quicktimer.cocolog-nifty.com/icefloe/2024/04/post-fad214.html

CLIコマンドラインツールを利用するには
セキュリティの設定が必要で
ユーザーの環境によっては『管理者認証』が必要になります。

初回実行時に警告が出る場合
この警告が出る場合、CLIツールを実行するには管理者権限が必要です
管理者権限が無い場合はCLIツールを利用出来ません。
20241011050502_520x2462

システム環境設定>プライバシーとセキュリティ>アプリケーションの実行許可
20241011050355_1416x277


アプリケーションの実行許可後の初回実行時に
再度警告が出ます
20241011050516_520x342

|

[archiveutility]圧縮解凍:Archive Utility

バンドルIDは
com.apple.archiveutility
リソースフォークやファイルの属性を保持した圧縮ができるので
Mac間でのファイルのやりとりには重宝する
Archive Utility 関連詰め合わせ
https://quicktimer.cocolog-nifty.com/icefloe/files/archive20utility.zip



場所
20241011051815_1494x718



設定
20241011051941_848x340

[bash]アーカイブユーティリティ設定
https://quicktimer.cocolog-nifty.com/icefloe/2023/05/post-9171f8.html

[mobileconfig]アーカイブユーティリティ
https://quicktimer.cocolog-nifty.com/icefloe/2023/05/post-c33181.html



[アーカイブユーティリティ]アーカイブユーティリティ.appで圧縮する
https://quicktimer.cocolog-nifty.com/icefloe/2023/05/post-1cade1.html

[アーカイブユーティリティ]アーカイブユーティリティ.appで圧縮する(複数ファイルを個別)
https://quicktimer.cocolog-nifty.com/icefloe/2023/05/post-556622.html

[アーカイブユーティリティ]アーカイブユーティリティ.appで圧縮する(フォルダを圧縮)
https://quicktimer.cocolog-nifty.com/icefloe/2023/05/post-11044e.html

|

[Unarchiver] Unarchiverのmobileconfigによる設定

入手先によってバンドルIDが異なるので
利用中のバンドルIDを確認します
サイト
com.macpaw.site.theunarchiver

AppleStore
cx.c3.theunarchiver


サンプルコード

サンプルソース(参考)
行番号ソース
001<dict>
002
003<key>OnboardingUserViewedWelcomeSlide</key>
004<true />
005<key>SUEnableAutomaticChecks</key>
006<true />
007<key>TUConfigInformationBannerOpened</key>
008<true />
009<key>TUConfigInformationBannerViewedCount</key>
010<integer>0</integer>
011<key>createFolder</key>
012<integer>2</integer>
013<key>deleteExtractedArchive</key>
014<true />
015<key>extractionDestination</key>
016<integer>1</integer>
017<key>filenameEncoding</key>
018<integer>8</integer>
019<key>folderModifiedDate</key>
020<integer>2</integer>
021<key>isFreshInstall</key>
022<true />
023<key>openExtractedFolder</key>
024<true />
025<key>userAgreedToNewTOSAndPrivacy</key>
026<true />
027
028<key>PayloadDisplayName</key>
029<string>The Unarchiver (サイトからダウンロード)</string>
030<key>PayloadIdentifier</key>
031<string>com.macpaw.site.theunarchiver.BBBBBBB-BBBBB-BBBBB-BBBBB-BBBBBBBBBB</string>
032<key>PayloadType</key>
033<string>com.macpaw.site.theunarchiver</string>
034<key>PayloadUUID</key>
035<string>BBBBBBB-BBBBB-BBBBB-BBBBB-BBBBBBBBBB</string>
036<key>PayloadVersion</key>
037<integer>1</integer>
038
039</dict>
AppleScriptで生成しました


サンプルコード

サンプルソース(参考)
行番号ソース
001
002
003<dict>
004
005<key>OnboardingUserViewedWelcomeSlide</key>
006<true />
007<key>SUEnableAutomaticChecks</key>
008<true />
009<key>TUConfigInformationBannerOpened</key>
010<true />
011<key>TUConfigInformationBannerViewedCount</key>
012<integer>0</integer>
013<key>createFolder</key>
014<integer>2</integer>
015<key>deleteExtractedArchive</key>
016<true />
017<key>extractionDestination</key>
018<integer>1</integer>
019<key>filenameEncoding</key>
020<integer>8</integer>
021<key>folderModifiedDate</key>
022<integer>2</integer>
023<key>isFreshInstall</key>
024<true />
025<key>openExtractedFolder</key>
026<true />
027<key>userAgreedToNewTOSAndPrivacy</key>
028<true />
029
030<key>PayloadDisplayName</key>
031<string>The Unarchiver (アプストアからインストール)</string>
032<key>PayloadIdentifier</key>
033<string>cx.c3.theunarchiver.AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAA</string>
034<key>PayloadType</key>
035<string>cx.c3.theunarchiver</string>
036<key>PayloadUUID</key>
037<string>AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAA</string>
038<key>PayloadVersion</key>
039<integer>1</integer>
040</dict>
AppleScriptで生成しました

|

非圧縮zipを作る(ファイル指定)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()

#############################
###ダイアログを前面に出す
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
############ デフォルトロケーション
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias

############UTIリスト
set listUTI to {"public.data"}
set strMes to ("ファイルを選んでください") as text
set strPrompt to ("ファイルを選んでください") as text
try
  ### ファイル選択時
  set listAliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as list
on error
log "エラーしました"
return "エラーしました"
end try


repeat with itemAliasFilePath in listAliasFilePath
  
  set strFilePath to (POSIX path of itemAliasFilePath) as text
  set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
  set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
  set ocidSaveFilePathURL to (ocidFilePathURL's URLByAppendingPathExtension:("zip"))
  #
  set ocidSaveFilePath to ocidSaveFilePathURL's |path|()
  set boolFileExists to (appFileManager's fileExistsAtPath:(ocidSaveFilePath) isDirectory:(false))
  if boolFileExists is true then
log "同名ファイルがある"
    set numCntNo to 1 as integer
    repeat
      set strSetValue to (numCntNo & ".zip") as text
      set ocidSaveFilePathURL to (ocidFilePathURL's URLByAppendingPathExtension:(strSetValue))
      set ocidSaveFilePath to ocidSaveFilePathURL's |path| as text
      set boolChkFileExists to (appFileManager's fileExistsAtPath:(ocidSaveFilePath) isDirectory:(false))
      if boolChkFileExists is false then
        set strSaveFilePath to ocidSaveFilePathURL's |path|() as text
        exit repeat
      end if
    end repeat
  else if boolFileExists is false then
log "同名ファイルが無いので処理する"
    set strSaveFilePath to ocidSaveFilePathURL's |path|() as text
  end if
  
  set strFilePath to ocidFilePathURL's |path| as text
  set strContainerDirPath to ocidContainerDirPathURL's |path| as text
  
  set strCommandText to ("pushd \"" & strContainerDirPath & "\" && '/usr/bin/zip' -0X \"" & strSaveFilePath & "\" \"" & strFilePath & "\"") as text
log strCommandText
do shell script strCommandText
  
end repeat





|

非圧縮zipを作る(フォルダ指定)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application


###Wクリックで起動した場合
on run
  set aliasDefaultLocation to (path to desktop from user domain) as alias
  set strPromptText to "フォルダをえらんでください"
  set strMesText to "フォルダをえらんでください"
  try
    set listFolderPath to (choose folder strMesText with prompt strPromptText default location aliasDefaultLocation with multiple selections allowed, invisibles and showing package contents) as list
  on error
log "エラーしました"
return "エラーしました"
  end try
open listFolderPath
end run

###ドロップで起動した場合
on open listFolderPath
  tell application "Finder"
    set strKind to (kind of (item 1 of listFolderPath)) as text
  end tell
  if strKind is not "フォルダ" then
return "フォルダ以外は処理しない"
  end if
  ####構造ファイルの名称を取得する
  repeat with itemFolderPath in listFolderPath
    set aliasFolderPath to itemFolderPath as alias
    tell application "Finder"
      tell folder aliasFolderPath
        set listContentsAlias to name of every folder as list
        set strDirName to name as text
      end tell
      set aliasContainerDirPath to (container of aliasFolderPath) as alias
    end tell
    set strContainerDirPath to (POSIX path of aliasContainerDirPath) as text
    set strDirPath to (POSIX path of aliasFolderPath) as text
    set strCommandText to ("pushd \"" & strDirPath & "\"") as text
log strCommandText
do shell script strCommandText
    
    set strCommandText to ("pushd \"" & strDirPath & "\" && '/usr/bin/zip' -0rX \"../" & strDirName & ".zip\" *") as text
log strCommandText
do shell script strCommandText
    
  end repeat
  
end open






|

[bash]UnarchiverDMGインストール


#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe

##################################
USER_WHOAMI=$(/usr/bin/whoami)
/bin/echo "実行ユーザー(whoami): $USER_WHOAMI"
###実行しているユーザー名
CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }')
/bin/echo "コンソールユーザー(scutil): $CONSOLE_USER"
###実行しているユーザー名
HOME_USER=$(/bin/echo "$HOME" | /usr/bin/awk -F'/' '{print $NF}')
/bin/echo "実行ユーザー(HOME): $HOME_USER"
###logname
LOGIN_NAME=$(/usr/bin/logname)
/bin/echo "ログイン名(logname): $LOGIN_NAME"
###UID
USER_NAME=$(/usr/bin/id -un)
/bin/echo "ユーザー名(id): $USER_NAME"
###STAT
STAT_USR=$(/usr/bin/stat -f%Su /dev/console)
/bin/echo "STAT_USR(console): $STAT_USR"
##################################
/bin/echo "インストール先確保" $HOME/Applications/Utilities
/bin/mkdir -p $HOME/Applications/Utilities
/bin/chmod 700 $HOME/Applications
/bin/chmod 755 $HOME/Applications/Utilities
/usr/bin/touch $HOME/Applications/.localized
/usr/bin/touch $HOME/Applications/Utilities/.localized
##################################
LIST_APPNAME=("unar" "Unarchiver")
for ITEM_APPNAME in "${LIST_APPNAME[@]}"; do
STR_PNO=$(/usr/bin/pgrep -f "$ITEM_APPNAME")
/bin/kill -9 "$STR_PNO"
done
##################################
STR_URL="https://dl.devmate.com/com.macpaw.site.theunarchiver/TheUnarchiver.dmg"
##ダウンロード先
STR_TMPDIRPATH=$(/usr/bin/mktemp -d)
/bin/chmod 777 "$STR_TMPDIRPATH"
/bin/echo "ダウンロード開始:" "$STR_TMPDIRPATH"
##生存確認
/usr/bin/curl -s --head "$STR_URL" >/dev/null
if [ $? -ne 0 ]; then
/bin/echo "エラー:URLの生存確認で失敗しました"
exit 1
fi
###リダイレクト先のURLを取得
STR_REDIRECT_URL=$(/usr/bin/curl -s -L -I -o /dev/null -w '%{url_effective}' "$STR_URL")
if [ $? -ne 0 ]; then
/bin/echo "エラー:リダイレクトの取得に失敗しました"
exit 1
fi
###ファイル名を取得
STR_FILE_NAME=$(/usr/bin/basename "$STR_REDIRECT_URL")
/bin/echo "ファイル名:$PKG_FILE_NAME"
###ダウンロード
/usr/bin/curl -L --retry 3 --retry-connrefused --retry-delay 3 -o "$STR_TMPDIRPATH/$STR_FILE_NAME" "$STR_URL"
if [ $? -ne 0 ]; then
/bin/echo "エラー:ダウンロードに失敗しました"
exit 1
fi
##################################
STR_DMG_PATH="$STR_TMPDIRPATH/$STR_FILE_NAME"
/usr/bin/hdiutil attach "$STR_DMG_PATH" -noverify -nobrowse -noautoopen
if [ $? -ne 0 ]; then
/bin/echo "エラー:ディスクのマウントで失敗しました"
exit 1
fi
##################################
STR_DIST_PATH="$HOME/Applications/Utilities/The Unarchiver.app/"
if [ -d "$STR_DIST_PATH" ]; then
/bin/echo "ファイルが存在します"
STR_TRASH_DIR=$(/usr/bin/mktemp -d "$HOME/.Trash/Unarchiver.XXXXXXXX")
/bin/chmod 777 "$STR_TRASH_DIR"
/bin/mv -f "$STR_DIST_PATH" "$STR_TRASH_DIR"
/bin/echo "古いファイルをゴミ箱に入れました"
fi
##################################
STR_ORG_PATH="/Volumes/The Unarchiver/The Unarchiver.app"
/usr/bin/ditto "$STR_ORG_PATH" "$STR_DIST_PATH"
if [ $? -ne 0 ]; then
/usr/bin/hdiutil detach "/Volumes/The Unarchiver" -force
/bin/echo "エラー:ファイルのコピーで失敗しました"
exit 1
fi
##################################
/usr/bin/hdiutil detach "/Volumes/The Unarchiver" -force
if [ $? -ne 0 ]; then
/usr/bin/hdiutil detach "/Volumes/The Unarchiver 1" -force
/usr/bin/hdiutil detach "/Volumes/The Unarchiver 2" -force
/bin/echo "エラー:ディスクのアンマウントに失敗しました"
exit 1
fi
##################################
LIST_BUNDLEID=("cx.c3.theunarchiver" "com.macpaw.site.theunarchiver")
for ITEM_BUNDLEID in "${LIST_BUNDLEID[@]}"; do
/bin/echo "$ITEM_BUNDLEID"
/usr/bin/defaults write "$ITEM_BUNDLEID" createFolder -integer 2
/usr/bin/defaults write "$ITEM_BUNDLEID" extractionDestination -integer 1
/usr/bin/defaults write "$ITEM_BUNDLEID" folderModifiedDate -integer 2
/usr/bin/defaults write "$ITEM_BUNDLEID" LaunchCount -integer 0
/usr/bin/defaults write "$ITEM_BUNDLEID" filenameEncoding -integer 8
/usr/bin/defaults write "$ITEM_BUNDLEID" TUConfigInformationBannerViewedCount -integer 0
/usr/bin/defaults write "$ITEM_BUNDLEID" OnboardingUserViewedWelcomeSlide -bool true
/usr/bin/defaults write "$ITEM_BUNDLEID" SUEnableAutomaticChecks -bool true
/usr/bin/defaults write "$ITEM_BUNDLEID" userAgreedToNewTOSAndPrivacy -bool true
/usr/bin/defaults write "$ITEM_BUNDLEID" isFreshInstall -bool true
/usr/bin/defaults write "$ITEM_BUNDLEID" TUConfigInformationBannerOpened -bool true
/usr/bin/defaults write "$ITEM_BUNDLEID" deleteExtractedArchive -bool true
/usr/bin/defaults write "$ITEM_BUNDLEID" TUConfigInformationBannerOpened -bool true
/bin/echo "基本設定を行いました"
done

/usr/bin/killall cfprefsd

/bin/echo "終了しました"
exit 0


|

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat 2024 Acrobat AddOn Acrobat Annotation Acrobat AppleScript Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat GentechAI Acrobat JS Acrobat JS Word Search Acrobat Maintenance Acrobat Manifest Acrobat Menu Acrobat Merge Acrobat Open Acrobat PDFPage Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat Print Acrobat Python Acrobat Reader Acrobat Reader Localized Acrobat Reference Acrobat Registered Products Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat URL List Mac Acrobat URL List Windows Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin ConfigCode Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin NetWork Admin Permission Admin Pkg Admin Power Management Admin Printer Admin Printer Basic Admin Printer Custompapers Admin SetUp Admin SMB Admin softwareupdate Admin Support Admin System Information Admin TCC Admin Tools Admin Umask Admin Users Admin Volumes Admin XProtect Adobe Adobe AUSST Adobe Bridge Adobe Documents Adobe FDKO Adobe Fonts Adobe Reference Adobe RemoteUpdateManager Adobe Sap Code AppKit Apple AppleScript AppleScript Duplicate AppleScript entire contents AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Video Applications AppStore Archive Archive Keka Attributes Automator BackUp Barcode Barcode Decode Barcode QR Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome Chromedriver CIImage CityCode CloudStorage Color Color NSColor Color NSColorList com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Desktop Position Device Diff Disk do shell script Dock Dock Launchpad DropBox Droplet eMail Encode % Encode Decode Encode HTML Entity Encode UTF8 Error EXIFData exiftool ffmpeg File File Name Finder Finder Window Firefox Folder FolderAction Font List FontCollections Fonts Fonts Asset_Font Fonts ATS Fonts Emoji Fonts Maintenance Fonts Morisawa Fonts Python Fonts Variable Foxit GIF github Guide HTML Icon Icon Assets.car Illustrator Image Events ImageOptim Input Dictionary iPhone iWork Javascript Jedit Ω Json Label Language Link locationd lsappinfo m3u8 Mail Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Microsoft Fonts Microsoft Office Microsoft Office Link Microsoft OneDrive Microsoft Teams Mouse Music Node Notes NSArray NSArray Sort NSAttributedString NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSGraphicsContext Crop NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMetadataItem NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSet NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSUbiquitous NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth PDF PDF Image2PDF PDF MakePDF PDF nUP PDF Pymupdf PDF Pypdf PDFContext PDFDisplayBox PDFImageRep PDFKit PDFKit Annotation PDFKit AnnotationWidget PDFKit DocumentPermissions PDFKit OCR PDFKit Outline PDFKit Start PDFPage PDFPage Rotation PDFView perl Photoshop PlistBuddy pluginkit plutil postalcode PostScript PowerShell prefPane Preview Python Python eyed3 Python pip QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver Script Editor Script Menu SF Symbols character id SF Symbols Entity Shortcuts Shortcuts Events sips Skype Slack Sound Spotlight sqlite StandardAdditions StationSearch Subtitles LRC Subtitles SRT Subtitles VTT Swift swiftDialog System Events System Settings TemporaryItems Terminal Text Text CSV Text MD Text TSV TextEdit Tools Translate Trash Twitter Typography UI Unit Conversion UTType valueForKeyPath Video VisionKit Visual Studio Code VMware Fusion Wacom Weather webarchive webp Wifi Windows XML XML EPUB XML HTML XML LSSharedFileList XML LSSharedFileList sfl2 XML LSSharedFileList sfl3 XML objectsForXQuery XML OPML XML Plist XML Plist System Events XML RSS XML savedSearch XML SVG XML TTML XML webloc XML xmllint XML XMP YouTube Zero Padding zoom