Results 1 to 3 of 3
  1. #1
    Script to re-date folder to contents logic problem
    I need to write an applescript to re-date folder(s) to the latest date of the folder contents.
    (Right, now I open a folder, open a file in there, make no changes and/or do not save, so the file modification date does not change, but the folder mod date does. I need it to show the same date as the last modified file.)
    I don't know how to do any of this, but I'll work it out!
    However, I have a logic problem that I can't work out.
    So, I need the script to cycle through all the files in a folder looking at their modification dates, and then if file B is older than file A I want to ignore it an go to file C, and if that file date is more recent than A, I want to keep C and ignore A.
    But, how do I get the first instance into the loop? I figured I need a known very old start date, say set compareDate to 01/01/01, but then, how do I leave that out of the loop for the second comparison?
    Am I explaining this well enough?


  2. #2
    Script to re-date folder to contents logic problem
    Mark FX's Avatar
    Member Since
    Aug 13, 2011
    West Sussex, UK
    Rep Power
    Hi emilycurious

    Your question seems a little confused to me, and I don't fully understand what you're asking for.
    Sometimes you've got to slow down and be more mathematical, and solve one problem at a time.

    I think you're asking how to find the file in any given folder with the latest modification date.

    This very basic example in AppleScript below, does that in you're Documents folder, but could be made to check any folder on your system.

    use AppleScript version "2.5"
    use scripting additions
    	set theDocumentsFolder to (path to documents folder from user domain) as text
    	tell application id ""
    		set theFilesList to (every item in folder theDocumentsFolder whose visible is true) as list
    		set theReferenceDate to date "Tuesday, 1 January 1901 at 01:01:01" as date
    		set theReferenceFile to missing value
    		repeat with theFile in theFilesList
    			set theFileProperties to (properties of theFile) as record
    			set theFileModDate to (modification date of theFileProperties) as date
    			if theFileModDate > theReferenceDate then
    				set theReferenceDate to theFileModDate as date
    				set theReferenceFile to theFile as alias
    			end if
    		end repeat
    	end tell
    	tell application id ""
    		open file theReferenceFile
    	end tell
    on error
    	return "An Error Occurred" as text
    end try
    return theReferenceFile
    Copy and paste the above code into a new Scipt Editor file, and it will open the file with the latest modification date.
    And also return an AppleScript alias reference to the file in the Script Editor's Result pane.
    That's the lowest view in the Script Editor window, if you are not familiar Script Editor, or haven't used it before.

    This might give you a start to what your trying to achieve.
    But explain more clearly how we can help you further.

    Regards Mark
    Last edited by Mark FX; 01-20-2017 at 07:26 PM.

  3. #3
    Quote Originally Posted by Mark FX View Post
    Sometimes you've got to slow down
    Many thanks Mark
    I owe you a beer.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. how do i view contents of a folder
    By Suzie68 in forum macOS - Operating System
    Replies: 2
    Last Post: 07-15-2014, 07:06 PM
  2. Backing up folder contents
    By wkp94 in forum macOS - Operating System
    Replies: 0
    Last Post: 10-05-2012, 04:44 PM
  3. Folder contents disappeared...Help!
    By clw in forum Running Windows (or anything else) on your Mac
    Replies: 0
    Last Post: 02-04-2011, 04:29 PM
  4. Deleting folder contents
    By odenkun in forum macOS - Operating System
    Replies: 2
    Last Post: 04-22-2009, 09:19 AM
  5. Replies: 0
    Last Post: 04-30-2008, 01:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts