As I mentioned, I tested the Shortcut that I posted previously on macOS Sequoia v15.6 without any errors and the designated creation date was applied to the selected document. Recheck your Shortcut.
I haven't had time to tweak the Swift code to be interactive like SetFile, but it does contain a function and examples of using that function that allow you to change either or both of creation and modification dates (and times).
A quick invocation after adding a file path and date/time info:
swift xSetFile.swift
/*
xSetFile.swift
Does what SetFile -d does and gives one the option of changing creation date,
modification date, or both depending upon what is passed to the setFileDates
function.
Presently lacking interactive capability, one can extend this to that functionality
by using CommandLine.arguments functionality.
*/
import Foundation
func setFileDates(filePath: String, creationDate: Date?, modificationDate: Date?) {
let fileManager = FileManager.default
var attributes: [FileAttributeKey: Any] = [:]
if let creationDate = creationDate {
attributes[.creationDate] = creationDate
}
if let modificationDate = modificationDate {
attributes[.modificationDate] = modificationDate
}
do {
try fileManager.setAttributes(attributes, ofItemAtPath: filePath)
print("Successfully updated file dates for: \(filePath)")
} catch {
print("Error setting file dates for \(filePath): \(error.localizedDescription)")
}
}
// Example usage:
let filePath = "/path/to/file" // Replace with the actual path to your file
// Set a specific creation date
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MM/dd/yyyy HH:mm:ss"
if let newCreationDate = dateFormatter.date(from: "01/01/2023 10:00:00") {
setFileDates(filePath: filePath, creationDate: newCreationDate, modificationDate: nil)
}
// Set a specific modification date
if let newModificationDate = dateFormatter.date(from: "02/15/2024 14:30:00") {
setFileDates(filePath: filePath, creationDate: nil, modificationDate: newModificationDate)
}
// Set both creation and modification dates
if let newCreationDate = dateFormatter.date(from: "03/20/2025 09:15:00"),
let newModificationDate = dateFormatter.date(from: "03/20/2025 11:45:00") {
setFileDates(filePath: filePath, creationDate: newCreationDate, modificationDate: newModificationDate)
}