BackUp

フォルダーコピー(Mac固有の情報をコピーしない)


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

#!/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


tell application "Finder"
  set aliasDefaultLocation to (path to desktop folder from user domain) as alias
end tell
######元
set strMes to "コピーする元フォルダを選んでください" as text
set strPrompt to "フォルダを選択してください" as text
try
  set aliasOrigDirPath to (choose folder strMes with prompt strPrompt default location aliasDefaultLocation with invisibles and showing package contents without multiple selections allowed) as alias
on error
  log "エラーしました"
return
end try
######先
set strMes to "コピー先のフォルダを選んでください" as text
set strPrompt to "フコピー先のォルダを選択してください" as text
try
  set aliasDistDirPath to (choose folder strMes with prompt strPrompt default location aliasDefaultLocation with invisibles and showing package contents without multiple selections allowed) as alias
on error
  log "エラーしました"
return
end try

###パス整形
set strOrigDirPath to POSIX path of aliasOrigDirPath as text
set strDistDirPath to POSIX path of aliasDistDirPath as text
###機種依存置き換え(エラー対策)
set strOrigDirPath to doReplace(strOrigDirPath, "`", "")
set strDistDirPath to doReplace(strDistDirPath, "`", "")
###ディスクフォーマットの違いによりコマンドの分岐
set aliasDistDirPath to POSIX file strDistDirPath as alias
###コピー先のディスク名
tell application "Finder"
  ###エイリアスを分解
  set fileFolderPath to folder aliasDistDirPath
  ###ディスク部分を取得
  set refDiskName to disk of fileFolderPath
  ###起動ディスク配下
  if refDiskName is startup disk then
    tell startup disk
      set strVolumeName to name as text
    end tell
  else
    set strVolumeName to refDiskName as text
  end if
end tell
####コピー先のディスクのフォーマット
tell application "System Events"
  tell disk strVolumeName
    set strDiskFormat to format as text
    ###通常コピー
    if strDiskFormat contains "Mac" then
      set strCommandText to ("/usr/bin/ditto \"" & strOrigDirPath & "\" \"" & strDistDirPath & "\"") as text
    else if strDiskFormat contains "NFS" then
      set strCommandText to ("/usr/bin/ditto \"" & strOrigDirPath & "\" \"" & strDistDirPath & "\"") as text
    else if strDiskFormat contains "APFS" then
      set strCommandText to ("/usr/bin/ditto \"" & strOrigDirPath & "\" \"" & strDistDirPath & "\"") as text
    else if strDiskFormat contains "Apple" then
      set strCommandText to ("/usr/bin/ditto \"" & strOrigDirPath & "\" \"" & strDistDirPath & "\"") as text
    else
      ###Mac固有の情報をコピーしない
      set strCommandText to ("/usr/bin/ditto --norsrc \"" & strOrigDirPath & "\" \"" & strDistDirPath & "\"") as text
    end if
  end tell
end tell


do shell script strCommandText




to doReplace(argOrignalText, argSearchText, argReplaceText)
  set strDelim to AppleScript's text item delimiters
  set AppleScript's text item delimiters to argSearchText
  set listDelim to every text item of argOrignalText
  set AppleScript's text item delimiters to argReplaceText
  set strReturn to listDelim as text
  set AppleScript's text item delimiters to strDelim
return strReturn
end doReplace

|

[バックアップ]差分バックアップ(同名ファイルは処理しない)


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

#!/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
set appFileManager to refMe's NSFileManager's defaultManager()

property refNSNotFound : a reference to 9.22337203685477E+18 + 5807

###コピー元 ディレクトリ
set strOrigDirPath to "/Volumes/HD-EDS-B/Shared/Musics/Music" as text
###保存先 ディレクトリ
set strDistDirPath to "/Volumes/NO NAME/contents/Musics/Music" as text

##対象のファイルのUTI サンプルは音楽ファイル
set listUTI to {"com.apple.m4a-audio", "public.mp3"} as list



#################################
###コピー元
set ocidOrigDirPathStr to refMe's NSString's stringWithString:(strOrigDirPath)
set ocidOrigDirPath to ocidOrigDirPathStr's stringByStandardizingPath()
set ocidOrigDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidOrigDirPath) isDirectory:true)

###コピー元
set ocidDistDirPathStr to refMe's NSString's stringWithString:(strDistDirPath)
set ocidDistDirPath to ocidDistDirPathStr's stringByStandardizingPath()
set ocidDistDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidDistDirPath) isDirectory:true)

#################################
###コンテンツ収集最下層まで
##プロパティ
set ocidProperty to {(refMe's NSURLIsDirectoryKey), (refMe's NSURLPathKey), (refMe's NSURLIsRegularFileKey), (refMe's NSURLContentTypeKey)}
set ocidOptions to (refMe's NSDirectoryEnumerationSkipsHiddenFiles)
set ocidEmuDict to appFileManager's enumeratorAtURL:(ocidOrigDirPathURL) includingPropertiesForKeys:(ocidProperty) options:(ocidOptions) errorHandler:(reference)
##Arrayに格納
set ocidEmuFileArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
set ocidEmuObject to (ocidEmuDict's allObjects)
ocidEmuFileArray's addObjectsFromArray:(ocidEmuObject)

#################################
###URL格納用のArray
set ocidFileURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
###全URLから対象のファイルパスを取得します
repeat with itemEmuFileURL in ocidEmuFileArray
  ####URLをforKeyで取り出し
  set listResult to (itemEmuFileURL's getResourceValue:(reference) forKey:(refMe's NSURLIsRegularFileKey) |error|:(reference))
  ###リストからNSURLIsRegularFileKeyのBOOLを取り出し
  set boolIsRegularFileKey to item 2 of listResult
  ####ファイルのみを(ディレクトリやリンボリックリンクは含まない)
  if boolIsRegularFileKey is (refMe's NSNumber's numberWithBool:true) then
    set listResult to (itemEmuFileURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error|:(reference))
    set ocidContentType to item 2 of listResult
    set strUTI to (ocidContentType's identifier) as text
    ####対象のファイルだけリストに加える
    if listUTI contains strUTI then
      ####リストにする
(ocidFileURLArray's addObject:(itemEmuFileURL))
    end if
  end if
end repeat

#################################
###本処理
repeat with itemFileURL in ocidFileURLArray
  ###対象のパス
  set strItemFilePath to (itemFileURL's |path|) as text
  set ocidItemPathString to (refMe's NSMutableString's alloc()'s initWithCapacity:0)
(ocidItemPathString's setString:(strItemFilePath))
  ###レンジを取得
  set ocidPathRange to refMe's NSMakeRange(0, ocidItemPathString's |length|)
  ###元のファイルパスから保存先ファイルパスを生成
  ##ディレクトリパスの置換
  set ocidOption to refMe's NSCaseInsensitiveSearch
(ocidItemPathString's replaceOccurrencesOfString:(ocidOrigDirPathStr) withString:(ocidDistDirPathStr) options:(ocidOption) range:(ocidPathRange))
  ###コマンド用のテキストにして
  set strDistFilePath to ocidItemPathString as text
  ###コピー先パス
  set ocidDistFilePath to ocidItemPathString's stringByStandardizingPath()
  ###ファイルの有無を確認
  set boolFileExist to (appFileManager's fileExistsAtPath:(ocidDistFilePath) isDirectory:(false))
  ###ファイルがなければ
  if boolFileExist = false then
    ###コピーする
    set strCommandText to ("/usr/bin/ditto \"" & strItemFilePath & "\" \"" & strDistFilePath & "\"") as text
    do shell script strCommandText
  end if
  
end repeat

display notification "処理終了" with title "処理が終了" subtitle "処理が終了しました" sound name "Sonumi"
log ">>>>>>>>>>>>処理終了<<<<<<<<<<<<<<<"
return ">>>>>>>>>>>>処理終了<<<<<<<<<<<<<<<"

|

[iPhone]バックアップの容量を調べる

#!/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



###アプリケーションサポートフォルダ
tell application "Finder"
    set aliasApplicationSupportFolder to path to application support folder from user domain as alias
end tell


### iPhoneのバックアップフォルダ
tell application "Finder"
    set aliasBackupFolder to folder "Backup" of folder "MobileSync" of folder aliasApplicationSupportFolder as alias
end tell

###  バックアップフォルダの中身
###ここで『フォルダの中身』を取得しています
tell application "Finder"
    set listInSideFolder to (list folder aliasBackupFolder without invisibles) as list
end tell

if listInSideFolder is {} then
    return "【情報】iPhoneのバックアップは,このMacにはありません"
end if


#### 順番にフォルダを処理する
repeat with objInSideFolder in listInSideFolder
    set strInSideFolder to objInSideFolder as text
    tell application "Finder"
        set aliasObjInSideFolder to folder strInSideFolder of folder aliasBackupFolder as alias
        tell folder aliasObjInSideFolder
            --->通常の処理はここで
            set strModificationDate to modification date as text
            log "バックアップは," & strModificationDate & "に取得した内容です"
        end tell
    end tell
    ####フォルダのサイズを取得します
    tell application "System Events" to set numFolderSize to size of aliasObjInSideFolder as number
    set strFolderSize to numFolderSize as text
    set AppleScript's text item delimiters to "E"
    set listFolderSize to every text item of strFolderSize
    set AppleScript's text item delimiters to ""
    set strFolderSize to item 1 of listFolderSize as text
    if strFolderSize contains "." then
        log "バックアップの容量は、" & strFolderSize & " GBです"
        return "バックアップの容量は、" & strFolderSize & " GBです"
    else if numFolderSize > 99999 then
        set strFolderSize to (numFolderSize / 100000) as text
        log "バックアップの容量は、" & strFolderSize & " MBです"
        return "バックアップの容量は、" & strFolderSize & " MBです"
    else
        set strFolderSize to (numFolderSize / 1000) as text
        log "バックアップの容量は、" & strFolderSize & " KBです"
        return "バックアップの容量は、" & strFolderSize & " KBです"
    end if
end repeat


set numCntBackUpFolder to (count of listInSideFolder) as number
if numCntBackUpFolder > 1 then
    log "【警告】このMacには," & numCntBackUpFolder & "台分のiPhoneのバックアップがあります"
    return "【警告】このMacには," & numCntBackUpFolder & "台分のiPhoneのバックアップがあります"
end if


#!/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

set objFileManager to refMe's NSFileManager's defaultManager()
##############################
### iPhoneのバックアップフォルダ
##############################
set ocidUserApplicationSupport to (objFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidUserApplicationSupportURL to item 1 of ocidUserApplicationSupport
set ocidBackupFilePathURL to ocidUserApplicationSupportURL's URLByAppendingPathComponent:"MobileSync/Backup" isDirectory:true
#####フォルダ等の有無を確認
set listSubPathResult to (objFileManager's contentsOfDirectoryAtURL:ocidBackupFilePathURL includingPropertiesForKeys:{refMe's NSURLPathKey} options:(refMe's NSDirectoryEnumerationSkipsHiddenFiles) |error|:(reference))
set ocidBackupFileArray to item 1 of listSubPathResult

log "バックアップは" & (count of ocidBackupFileArray) & "点あります"
##############################
### サイズチェック
##############################

repeat with itemBackupFileArray in ocidBackupFileArray
    ###フォルダ名
    set ocidFileName to itemBackupFileArray's lastPathComponent()
    ####フォルダの下層までenumeratorで取得する
    set numDirSize to 0
    set ocidEmuDict to (objFileManager's enumeratorAtURL:itemBackupFileArray includingPropertiesForKeys:{refMe's NSURLTotalFileSizeKey} options:0 errorHandler:(reference))
    #### enumeratorからURLのリストにする
    set ocidEmuFileURLArray to ocidEmuDict's allObjects()
    ####URLの分だけ繰り返し
    repeat with itemEmuFileURL in ocidEmuFileURLArray
        ###ファイルサイズを取得して
        set listResult to (itemEmuFileURL's getResourceValue:(reference) forKey:(refMe's NSURLTotalFileSizeKey) |error|:(reference))
        set ocidURLSIze to item 2 of listResult
        ####値が戻れば加算していく
        if ocidURLSIze is not (missing value) then
            set numDirSize to numDirSize + (ocidURLSIze as real)
        end if
    end repeat
    ####合計サイズを整形
    set numDirSize to numDirSize / (1024 ^ 3) as integer
    
    log "フォルダ" & (ocidFileName as text) & "のサイズは,約" & numDirSize & "GBです"
    
end repeat

|

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat AddOn Acrobat Annotation Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat JS Acrobat Manifest Acrobat Menu Acrobat Open Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat python Acrobat Reader Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin Support Admin System Information Admin Tools Admin Users Admin Volumes Adobe Adobe FDKO Adobe RemoteUpdateManager AppKit Apple AppleScript AppleScript do shell script AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript System Events AppleScript System Events Plist AppleScript Video Applications AppStore Archive Attributes Automator BackUp Barcode Barcode QR Barcode QR Decode Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome CIImage CityCode CloudStorage Color com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Device Diff Disk Dock DropBox Droplet eMail Encode % Encode Decode Encode UTF8 Error EXIFData ffmpeg File Finder Firefox Folder FolderAction Fonts GIF github Guide HTML HTML Entity Icon Illustrator Image Events Image2PDF ImageOptim iPhone iWork Javascript Jedit Json Label Leading Zero List locationd LRC lsappinfo LSSharedFileList m3u8 Mail MakePDF Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Mouse Music NetWork Notes NSArray NSArray Sort NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSColor NSColorList NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSPrintOperation NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth OneDrive PDF PDFAnnotation PDFAnnotationWidget PDFContext PDFDisplayBox PDFDocumentPermissions PDFImageRep PDFKit PDFnUP PDFOutline perl Photoshop PlistBuddy pluginkit postalcode PostScript prefPane Preview Python QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver SF Symbols character id SF Symbols Entity sips Skype Slack Sound Spotlight sqlite SRT StandardAdditions Swift System Settings TCC 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 webarchive webp Wifi Windows XML XML EPUB XML OPML XML Plist XML RSS XML savedSearch XML SVG XML TTML XML webloc XML XMP YouTube zoom