Skocz do zawartości

Witaj!

Zaloguj lub Zarejestruj się aby uzyskać pełny dostęp do forum.

Zdjęcie
- - - - -

Przydatny skrypt do zmiany daty utworzenia pliku


  • Zaloguj się, aby dodać odpowiedź
Brak odpowiedzi do tego tematu

#1 przemekf

przemekf
  • 1 308 postów
  • SkądŁódź

Napisano 19 kwietnia 2007 - 21:59

Witam,

Czasami trzeba na szybko zmienić datę utworzenia dużej liczby plików.
Znalazłem odpowiedni Apple Script:
http://www.macosxhin...060703160750583
Bardzo ładnie działa ten z komentarza, nie potrzeba zewnętrznej aplikacji, wystarczy zapisać w Edytorze jako aplikacja :)

Dla leniwych:

-- ChangeCreationDate
-- version 1.0, Daniel A. Shockley (http://www.danshockley.com)
-- idea suggested by spacericker9k on macosxhints.com, at:
-- http://www.macosxhin...060703160750583

on run

-- some coding formatted to keep the individual lines shorter

set dialogMsg to "Choose a folder of files to change, or file(s)?"
set buttonChoices to {"Cancel", "Folder", "Files"}
set openChoice to button returned of (display dialog dialogMsg buttons buttonChoices default button "Files")

if openChoice is "Files" then
set chooseFileDialog to "Choose the file(s) you want to change:"
set fileList to choose file with prompt chooseFileDialog with multiple selections allowed

else if openChoice is "Folder" then
set oneFolder to choose folder with prompt "Choose the folder whose files you want to change:"
tell application "Finder"
set fileList to (files of oneFolder) as alias list
end tell

end if

changeCreationDate(fileList)

end run


on open someItems
-- someItems could be files or folders - will only process FILES

changeCreationDate(someItems)

end open


on changeCreationDate(fileList)
-- version 1.0, Daniel A. Shockley (http://www.danshockley.com)

-- for now, just handle files, not folders
set dialogMsg to "Please choose a new creation date for the file(s)."
set newCreationDate to date (text returned of (display dialog dialogMsg default answer ""))

set creationDateString to year of newCreationDate as string
set creationDateString to creationDateString & text -2 thru -1 of ("0" & getMonthNum(newCreationDate) as string)
set creationDateString to creationDateString & text -2 thru -1 of ("0" & day of newCreationDate as string)
set creationDateString to creationDateString & text -2 thru -1 of ("0" & hours of newCreationDate as string)
set creationDateString to creationDateString & text -2 thru -1 of ("0" & minutes of newCreationDate as string)
set creationDateString to creationDateString & "." & text -2 thru -1 of ("0" & seconds of newCreationDate as string)

repeat with oneItem in fileList

if folder of (info for oneItem without size) is false then

set shellCommand to "touch -t " & creationDateString & " " & quoted form of POSIX path of oneItem

set logMsg to ("Changed creation date of file '" & oneItem as string) & "' to " & newCreationDate as string
logConsole("changeCreationDate", logMsg)

do shell script shellCommand

end if

end repeat


end changeCreationDate



on getMonthNum(theDate)
-- French Vanilla, by Emmanuel Lévy
--set theDate to the current date --or any other date
copy theDate to b
set the month of b to January
set monthNum to (1 + (theDate - b + 1314864) div 2629728)
return monthNum
end getMonthNum



on logConsole(processName, consoleMsg)
-- version 1.5 - Daniel A. Shockley, http://www.danshockley.com
-- 1.5- uses standard date-stamp format
set timeStamp to do shell script "date +\"%Y-%m-%d %H:%M:%S\""
set hostName to do shell script "hostname -s" & space
set logMsg to (return & timeStamp & space & hostName & space & processName & ":" & space & consoleMsg)
set shellCommand to "echo" & space & quoted form of logMsg & " >> /dev/console"

do shell script shellCommand

end logConsole

Pozdrawiam

Przemek




Użytkownicy przeglądający ten temat: 1

0 użytkowników, 1 gości, 0 anonimowych