Become a MacRumors Supporter for $25/year with no ads, private forums, and more!

Mac Change the "modified date" of a folder (AppleScript)

juzernejm

macrumors newbie
Original poster
Mar 13, 2015
28
0
Hi all

I have an issue with a Windows machine I control from a mac.
From time to time, when I force this PC to shutdown (I have no choice)
The folders contained in a certain directory all change their 'modified date' to the current day.
And that's bad, because I have no way to see the chronological order I created them.

Luckily, inside each of these folders, the files are all with the correct 'modified date'.

Lately I've been trying to play a bit with Applescript.. so I wonder if there is a way to:
copy the 'modified date' from the files to their respective folder.

Thanks.
 

juzernejm

macrumors newbie
Original poster
Mar 13, 2015
28
0
I imagine it is doable but I just started scripting (and have no programming background).
I don't know how to scructure the script.
 
Comment

juzernejm

macrumors newbie
Original poster
Mar 13, 2015
28
0
very helpful

edit:

Like I said, I just started to learn programming (i don't know/care if that's the right term).
Well after a few days of intense research/reading on the matter I can tell that the way we learn it's very inefficient.
In most of the cases one has in mind what the machine should do, but we are stuck because we are talking to a machine that needs lines of code even for th simplest of commands. It would take me a second to ask that to a human. But we don't do that. We have to reinvent the wheel all the time starting from scratch and learn a whole new language (if not more) just to realize that it will never be enough. What a colossal waste of time. I'm sure one day this madness will end. This fear to share our knowledge with others (it's ok if who's asking for help has the $$$ of course).

I am a graphic designer. When someone asks me how to do something in photoshop or indesign, I don't point them to the user manual. We all have something to offer to each-other. So don't think you are special because you know something the other doesn't. You help with what you know and in exchange you'll have a whole world that will do the same with you with what you don't know. In this way we help each-other, learn faster and don't have to waste countless hours talking to a machine.

I have nothing against anyone or the site.
I don't want to argue I'm just saying what I think.
Maybe it's just frustration after a hard period of learning and it will pass..
and maybe I will laugh at what I wrote here after a few months (although I doubt it) xD
 
Last edited:
Comment

dmi

macrumors regular
Dec 21, 2010
121
3
Are the folders on the mac or the Windows machine?
 
Last edited:
Comment

juzernejm

macrumors newbie
Original poster
Mar 13, 2015
28
0
The folders are on the Windows machine. And from what I found out googling, it is harder to do this from another machine because of permissions set on the Windows machine.
So for the moment I'm trying to solve this on the Windows machine.
I found a script for PowerShell that almost does what I need. This one:

Code:
Get-ChildItem $root | Where-Object {$_.PSIsContainer} | Foreach-Object{

# get the oldest file for the current directory object
$oldest = Get-ChildItem $_.FullName | Sort-Object LastWriteTime | Select-Object LastWriteTime -Last 1

if($oldest)
{
# oldest object found, set current directory LastWriteTime
$_ | Set-ItemProperty -Name CreationTime -Value $oldest.LastWriteTime
$_ | Set-ItemProperty -Name LastWriteTime -Value $oldest.LastWriteTime
}
else
{
# current directory is empty, directory LastWriteTime is left unchanged
Write-Warning "Directory '$($_.FullName)' is empty, skiping..."
}
}

The problem is that the "last modified" element inside these folders sometimes are subfolders that also get the current date as the "modified date". So it works but it's useless because it is set to copy the most recent element on the folder and since subfolders are modified for last, it copies that and puts it to the parent folder (which has the same date). I'm looking if I can find how to make this code look the files inside the folder and not the folders (subfolders).

In this code I see it uses a command to copy the last modified item inside these folders.
Is it possible to make it look for the first modified item of the folders (the oldest file, chronologically)?
 
Last edited:
Comment

superscape

macrumors 6502a
Feb 12, 2008
931
218
East Riding of Yorkshire, UK
I feel your pain, I too used to be a graphic designer and made the transition to being a programmer over a number of years.

If you're serious about learning to program then sooner or later you're going to have to do some reading of manuals and working through tutorials. There's no way around that. Learning to code and actually doing the coding *is* time consuming and laborious. Hopefully though, after that time spent coding you will have a script or app that will make life easier and save enough time and/or solve enough problems to justify your efforts.

Generally speaking, you'll find that folks are very likely to help you if you post the code you have so far so we can see what might be going wrong. If you don't then your post comes across as, "Do my work for me", instead of, "I'm stuck with *this* part of my work - help."

Pointing you at an appropriate tutorial and offering to help if you get stuck is actually very helpful indeed. And having read that, Kryten's post tells you exactly where to look in the scripting dictionary.
 
Comment

juzernejm

macrumors newbie
Original poster
Mar 13, 2015
28
0
Yes, I’m already reading some books and watching some videos. I see that I learn better when I listen to someone. So video courses are great. But I miss sometime the interaction with someone more experienced. So I’m looking for a way to solve that. I’m not finding videos on AppleScript so I’m going also for generic programming video courses (to have the foundamentals at least). But I agree with you, it takes time. But I also think that things could be done better, if we took a less individualistic approach.
 
Last edited:
Comment

juzernejm

macrumors newbie
Original poster
Mar 13, 2015
28
0
"pair-programming".. didn't know about that. Thanks a lot blaster_boy!
 
Comment
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.