- on find by stringForName
- set savedDelimiters to AppleScript's text item delimiters
- set AppleScript's text item delimiters to return
- set theResult to text items of (do shell script "fname=\"$(basename " & quoted form of stringForName & ")\";mdfind 'kMDItemDisplayName == \"'\"$fname\"'\"' | sort")
- set AppleScript's text item delimiters to savedDelimiters
- return theResult
- end find
- on optimize for paths
- set destinationPaths to {}
- set holdDestinationPaths to {}
- set newestFile to missing value
- repeat with thePath in paths
- try
- tell application "Finder" to set modificationDate to modification date of file (me's POSIX file thePath)
- if newestFile is not missing value and modificationDate < date of newestFile then
- set holdDestinationPaths to holdDestinationPaths & {thePath}
- else
- if newestFile is not missing value then
- set destinationPaths to destinationPaths & {filePath of newestFile} & holdDestinationPaths
- set holdDestinationPaths to {}
- end if
- set newestFile to {filePath:thePath, date:modificationDate}
- end if
- end try
- end repeat
- return {source:filePath of newestFile, destinations:(destinationPaths & holdDestinationPaths)}
- end optimize
- on synchronize by keyFilePath
- set copyPath to optimize for (find by keyFilePath)
- if (count of destinations of copyPath) is 0 then return
- set destinations of copyPath to choose from list destinations of copyPath OK button name "Copy" with title "Update the same files" with prompt "Copy “" & source of copyPath & "” to:" with multiple selections allowed
- if (count of destinations of copyPath) is 0 then return
- tell application "Finder"
- set sourceObject to file (me's POSIX file (source of copyPath))
- set destinaationObjects to {}
- set destinationContainers to {}
- repeat with thePath in destinations of copyPath
- set destinaationObject to file (me's POSIX file thePath)
- set destinaationObjects to destinaationObjects & {destinaationObject}
- set destinationContainers to destinationContainers & {container of destinaationObject}
- end repeat
- try
- delete destinaationObjects
- on error message
- display dialog message
- end try
- repeat with theContainer in destinationContainers
- try
- duplicate sourceObject to theContainer
- on error message
- display dialog message
- end try
- end repeat
- end tell
- end synchronize
- on open droppedItems
- if (count of droppedItems) is 0 then return
- synchronize by POSIX path of item 1 of droppedItems
- end open
- -- for example
- synchronize by "hoge.txt"
- synchronize by "../../Hoge/Desktop/hoge.txt"
- synchronize by "/Users/Hoge/Desktop/hoge.txt"
Sample